|
@@ -99,53 +99,61 @@ bool isBitSet(uint8_t value, uint8_t n) {
|
|
|
}
|
|
|
|
|
|
//Handle modifying key set or unset
|
|
|
-void keyboard_modifying_key_set(uint8_t key) {
|
|
|
- if (key & 0x01) { // Bit 0 = KEY_LEFT_CTRL
|
|
|
- Keyboard_press(KEY_LEFT_CTRL);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_LEFT_CTRL);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x02) { // Bit 1 = KEY_LEFT_SHIFT
|
|
|
- Keyboard_press(KEY_LEFT_SHIFT);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_LEFT_SHIFT);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x04) { // Bit 2 = KEY_LEFT_ALT
|
|
|
- Keyboard_press(KEY_LEFT_ALT);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_LEFT_ALT);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x08) { // Bit 3 = KEY_LEFT_GUI
|
|
|
- Keyboard_press(KEY_LEFT_GUI);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_LEFT_GUI);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x10) { // Bit 4 = KEY_RIGHT_CTRL
|
|
|
- Keyboard_press(KEY_RIGHT_CTRL);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_RIGHT_CTRL);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x20) { // Bit 5 = KEY_RIGHT_SHIFT
|
|
|
- Keyboard_press(KEY_RIGHT_SHIFT);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_RIGHT_SHIFT);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x40) { // Bit 6 = KEY_RIGHT_ALT
|
|
|
- Keyboard_press(KEY_RIGHT_ALT);
|
|
|
- } else {
|
|
|
- Keyboard_release(KEY_RIGHT_ALT);
|
|
|
- }
|
|
|
-
|
|
|
- if (key & 0x80) { // Bit 7 = KEY_RIGHT_GUI
|
|
|
- Keyboard_press(KEY_RIGHT_GUI);
|
|
|
+void keyboard_modifying_key_set(bool isPress, uint8_t key) {
|
|
|
+ if (isPress) {
|
|
|
+ switch (key) {
|
|
|
+ case PAYLOAD_KEY_LEFT_CTRL:
|
|
|
+ Keyboard_press(KEY_LEFT_CTRL);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_LEFT_SHIFT:
|
|
|
+ Keyboard_press(KEY_LEFT_SHIFT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_LEFT_ALT:
|
|
|
+ Keyboard_press(KEY_LEFT_ALT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_LEFT_GUI:
|
|
|
+ Keyboard_press(KEY_LEFT_GUI);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_CTRL:
|
|
|
+ Keyboard_press(KEY_RIGHT_CTRL);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_SHIFT:
|
|
|
+ Keyboard_press(KEY_RIGHT_SHIFT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_ALT:
|
|
|
+ Keyboard_press(KEY_RIGHT_ALT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_GUI:
|
|
|
+ Keyboard_press(KEY_RIGHT_GUI);
|
|
|
+ return;
|
|
|
+ }
|
|
|
} else {
|
|
|
- Keyboard_release(KEY_RIGHT_GUI);
|
|
|
+ switch (key) {
|
|
|
+ case PAYLOAD_KEY_LEFT_CTRL:
|
|
|
+ Keyboard_release(KEY_LEFT_CTRL);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_LEFT_SHIFT:
|
|
|
+ Keyboard_release(KEY_LEFT_SHIFT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_LEFT_ALT:
|
|
|
+ Keyboard_release(KEY_LEFT_ALT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_LEFT_GUI:
|
|
|
+ Keyboard_release(KEY_LEFT_GUI);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_CTRL:
|
|
|
+ Keyboard_release(KEY_RIGHT_CTRL);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_SHIFT:
|
|
|
+ Keyboard_release(KEY_RIGHT_SHIFT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_ALT:
|
|
|
+ Keyboard_release(KEY_RIGHT_ALT);
|
|
|
+ return;
|
|
|
+ case PAYLOAD_KEY_RIGHT_GUI:
|
|
|
+ Keyboard_release(KEY_RIGHT_GUI);
|
|
|
+ return;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -282,11 +290,11 @@ uint8_t keyboard_emulation(uint8_t subtype, uint8_t value) {
|
|
|
return resp_invalid_key_value;
|
|
|
Keyboard_release(value);
|
|
|
return resp_ok;
|
|
|
- case SUBTYPE_KEYBOARD_MODIFIER_SET:
|
|
|
- keyboard_modifying_key_set(value);
|
|
|
+ case SUBTYPE_KEYBOARD_MODIFIER_PRESS:
|
|
|
+ keyboard_modifying_key_set(true, value);
|
|
|
return resp_ok;
|
|
|
- case SUBTYPE_KEYBOARD_MODIFIER_CLEAR:
|
|
|
- keyboard_modifying_key_set(0x00);
|
|
|
+ case SUBTYPE_KEYBOARD_MODIFIER_RELEASE:
|
|
|
+ keyboard_modifying_key_set(false, value);
|
|
|
return resp_ok;
|
|
|
case SUBTYPE_KEYBOARD_FUNCTKEY_PRESS:
|
|
|
if (!is_funckey(value))
|