浏览代码

Finished keyboard mapping

Toby Chui 1 周之前
父节点
当前提交
75c4f0d100

+ 30 - 3
remdeskd/mod/remdeshid/hidcomm.go

@@ -69,9 +69,36 @@ func ConvHIDCommandToBytes(cmd HIDCommand) ([]byte, error) {
 			data = append(data, numpadKeyToByte(string(cmd.Data)))
 			return data, nil
 		} else if cmd.Data == "NumLock" {
-			//Special Key: NumLock
-			//TODO: Implement NumLock
-			return nil, fmt.Errorf("numLock not implemented")
+			if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
+				data = append(data, SUBTYPE_KEYBOARD_SPECIAL_NUMLOCK)
+				data = append(data, 0x00)
+				return data, nil
+			}
+			return nil, fmt.Errorf("numLock do not support key up")
+		} else if cmd.Data == "Pause" {
+			if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
+				data = append(data, SUBTYPE_KEYBOARD_SPECIAL_PAUSE)
+				data = append(data, 0x00)
+				return data, nil
+			}
+
+			return nil, fmt.Errorf("pause do not support key up")
+		} else if cmd.Data == "PrintScreen" {
+			if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_UP {
+				data = append(data, SUBTYPE_KEYBOARD_SPECIAL_PRINT_SCREEN)
+				data = append(data, 0x00)
+				return data, nil
+			}
+
+			return nil, fmt.Errorf("printScreen do not support key down")
+		} else if cmd.Data == "ScrollLock" {
+			if cmd.EventSubType == FRONTEND_SUBTYPE_KEYBOARD_KEY_DOWN {
+				data = append(data, SUBTYPE_KEYBOARD_SPECIAL_SCROLL_LOCK)
+				data = append(data, 0x00)
+				return data, nil
+			}
+
+			return nil, fmt.Errorf("scrollLock do not support key up")
 		} else if cmd.Data == "ContextMenu" {
 			//Special Key: ContextMenu
 			//TODO: Implement ContextMenu

+ 18 - 14
remdeskd/mod/remdeshid/hidconv.go

@@ -37,20 +37,24 @@ const (
 	FRONTEND_SUBTYPE_KEYBOARD_KEY_CLICK = "kc"
 
 	// USBKVM Keyboard Subtypes
-	SUBTYPE_KEYBOARD_ASCII_WRITE        = 0x01
-	SUBTYPE_KEYBOARD_ASCII_PRESS        = 0x02
-	SUBTYPE_KEYBOARD_ASCII_RELEASE      = 0x03
-	SUBTYPE_KEYBOARD_MODIFIER_PRESS     = 0x04
-	SUBTYPE_KEYBOARD_MODIFIER_RELEASE   = 0x05
-	SUBTYPE_KEYBOARD_FUNCTKEY_PRESS     = 0x06
-	SUBTYPE_KEYBOARD_FUNCTKEY_RELEASE   = 0x07
-	SUBTYPE_KEYBOARD_OTHERKEY_PRESS     = 0x08
-	SUBTYPE_KEYBOARD_OTHERKEY_RELEASE   = 0x09
-	SUBTYPE_KEYBOARD_NUMPAD_PRESS       = 0x0A
-	SUBTYPE_KEYBOARD_NUMPAD_RELEASE     = 0x0B
-	SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL = 0xFD
-	SUBTYPE_KEYBOARD_SPECIAL_RESET      = 0xFE
-	SUBTYPE_KEYBOARD_SPECIAL_RESERVED   = 0xFF
+	SUBTYPE_KEYBOARD_ASCII_WRITE          = 0x01
+	SUBTYPE_KEYBOARD_ASCII_PRESS          = 0x02
+	SUBTYPE_KEYBOARD_ASCII_RELEASE        = 0x03
+	SUBTYPE_KEYBOARD_MODIFIER_PRESS       = 0x04
+	SUBTYPE_KEYBOARD_MODIFIER_RELEASE     = 0x05
+	SUBTYPE_KEYBOARD_FUNCTKEY_PRESS       = 0x06
+	SUBTYPE_KEYBOARD_FUNCTKEY_RELEASE     = 0x07
+	SUBTYPE_KEYBOARD_OTHERKEY_PRESS       = 0x08
+	SUBTYPE_KEYBOARD_OTHERKEY_RELEASE     = 0x09
+	SUBTYPE_KEYBOARD_NUMPAD_PRESS         = 0x0A
+	SUBTYPE_KEYBOARD_NUMPAD_RELEASE       = 0x0B
+	SUBTYPE_KEYBOARD_SPECIAL_PAUSE        = 0xF9
+	SUBTYPE_KEYBOARD_SPECIAL_PRINT_SCREEN = 0xFA
+	SUBTYPE_KEYBOARD_SPECIAL_SCROLL_LOCK  = 0xFB
+	SUBTYPE_KEYBOARD_SPECIAL_NUMLOCK      = 0xFC
+	SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL   = 0xFD
+	SUBTYPE_KEYBOARD_SPECIAL_RESET        = 0xFE
+	SUBTYPE_KEYBOARD_SPECIAL_RESERVED     = 0xFF
 
 	// Numpad Buttons IDs
 	PAYLOAD_KEYBOARD_NUMPAD_0       = 0x00

+ 2 - 1
remdeskd/www/index.html

@@ -84,7 +84,8 @@
                     }
                 }else if (isNumpadEvent(event)){
                     socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: "NUMPAD_" + key }));
-                
+                }else if (key == "NumLock"){
+                   //Do nothing, release is hardware offloaded
                 } else {
                     socket.send(JSON.stringify({ t: 'kw', s: 'ku', d: key }));
                 }

+ 53 - 12
usbkvm/usbkvm_fw/keyboard_emu.ino

@@ -13,18 +13,13 @@
   0x03 = keyboard release
     (ASCII bytes in range of 32 to 127)
 
-  0x04 = Modifier key combination set (bit flags in payload)
-    Bit 0 (0x01) = KEY_LEFT_CTRL
-    Bit 1 (0x02) = KEY_LEFT_SHIFT
-    Bit 2 (0x04) = KEY_LEFT_ALT
-    Bit 3 (0x08) = KEY_LEFT_GUI
-    Bit 4 (0x10) = KEY_RIGHT_CTRL
-    Bit 5 (0x20) = KEY_RIGHT_SHIFT
-    Bit 6 (0x40) = KEY_RIGHT_ALT
-    Bit 7 (0x80) = KEY_RIGHT_GUI
-  0x05 = Modifier key combination reset 
-
-  0x07 = Function key combinartion write
+  0x04 = Modifier key combination press 
+  0x05 = Modifier key combination release 
+    See usbkvm_fw.h Modifier Keys IDs defination
+  
+  0x06 = Function key press
+  0x07 = Function key release
+    (IDs follows USB_HID numbers)
     0xC2 = KEY_F1
     0xC3 = KEY_F2
     0xC4 = KEY_F3
@@ -37,6 +32,7 @@
   
   0x08 = Other keys press
   0x09 = Other keys release
+    (IDs follows USB_HID numbers)
     0xDA = KEY_UP_ARROW
     0xD9 = KEY_DOWN_ARROW
     0xD8 = KEY_LEFT_ARROW
@@ -53,6 +49,10 @@
     0xD5 = KEY_END
     0xC1 = KEY_CAPS_LOCK
 
+  0x0A = Numpad key press
+  0x0B = Numpad key release
+    See usbkvm_fw.h Numpad Buttons IDs defination
+
   -- Special Opcode --
   0xFE = Ctrl + Alt + Delete
   0xFF = Reset all keys state
@@ -275,6 +275,9 @@ uint8_t keyboard_emulation(uint8_t subtype, uint8_t value) {
   //Check if the input is a supported ascii value
 
   switch (subtype) {
+    /*
+      Alphanumerical Key-events
+    */
     case SUBTYPE_KEYBOARD_ASCII_WRITE:
       if (!is_ascii(value))
         return resp_invalid_key_value;
@@ -290,12 +293,18 @@ uint8_t keyboard_emulation(uint8_t subtype, uint8_t value) {
         return resp_invalid_key_value;
       Keyboard_release(value);
       return resp_ok;
+    /*
+      Modifier Key-events
+    */
     case SUBTYPE_KEYBOARD_MODIFIER_PRESS:
       keyboard_modifying_key_set(true, value);
       return resp_ok;
     case SUBTYPE_KEYBOARD_MODIFIER_RELEASE:
       keyboard_modifying_key_set(false, value);
       return resp_ok;
+    /*
+      Function Key-events (F1 to F24)
+    */
     case SUBTYPE_KEYBOARD_FUNCTKEY_PRESS:
       if (!is_funckey(value))
         return resp_invalid_key_value;
@@ -306,6 +315,9 @@ uint8_t keyboard_emulation(uint8_t subtype, uint8_t value) {
         return resp_invalid_key_value;
       Keyboard_release(value);
       return resp_ok;
+    /*
+      Other Key-events
+    */
     case SUBTYPE_KEYBOARD_OTHERKEY_PRESS:
       if (!is_validkeys(value))
         return resp_invalid_key_value;
@@ -316,6 +328,9 @@ uint8_t keyboard_emulation(uint8_t subtype, uint8_t value) {
         return resp_invalid_key_value;
       Keyboard_release(value);
       return resp_ok;
+    /*
+      Numpad Key-events
+    */
     case SUBTYPE_KEYBOARD_NUMPAD_PRESS:
       if (value > PAYLOAD_NUMPAD_NUMLOCK)
         return resp_invalid_key_value;
@@ -326,6 +341,32 @@ uint8_t keyboard_emulation(uint8_t subtype, uint8_t value) {
         return resp_invalid_key_value;
       numpad_key_set(false, value);
       return resp_ok;
+    /* 
+      Hardware Offload Key-events 
+
+      These key-events are offloaded to hardware (the MCU)
+      for handling the press and release events
+    */
+    case SUBTYPE_KEYBOARD_SPECIAL_PAUSE:
+      Keyboard_press('\320');
+      delay(100);
+      Keyboard_release('\320');
+      return resp_ok;
+    case SUBTYPE_KEYBOARD_SPECIAL_PRINT_SCREEN:
+      Keyboard_press('\316');
+      delay(100);
+      Keyboard_release('\316');
+      return resp_ok;
+    case SUBTYPE_KEYBOARD_SPECIAL_SCROLL_LOCK:
+      Keyboard_press('\317');
+      delay(100);
+      Keyboard_release('\317');
+      return resp_ok;
+    case SUBTYPE_KEYBOARD_SPECIAL_NUMLOCK:
+      Keyboard_press('\333');
+      delay(100);
+      Keyboard_release('\333');
+      return resp_ok;
     case SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL:
       // Press Ctrl + Alt + Del
       Keyboard_press(KEY_LEFT_CTRL);

+ 18 - 14
usbkvm/usbkvm_fw/usbkvm_fw.h

@@ -26,20 +26,24 @@
 #define SUBTYPE_RESERVED 0x00
 
 /* Keyboard Subtypes */
-#define SUBTYPE_KEYBOARD_ASCII_WRITE 0x01         // Write ASCII characters (32-127)
-#define SUBTYPE_KEYBOARD_ASCII_PRESS 0x02         // Press a key (ASCII 32-127)
-#define SUBTYPE_KEYBOARD_ASCII_RELEASE 0x03       // Release a key (ASCII 32-127)
-#define SUBTYPE_KEYBOARD_MODIFIER_PRESS 0x04      // Modifier key write (bit flags)
-#define SUBTYPE_KEYBOARD_MODIFIER_RELEASE 0x05    // Modifier key press (bit flags)
-#define SUBTYPE_KEYBOARD_FUNCTKEY_PRESS 0x06      //Function key press
-#define SUBTYPE_KEYBOARD_FUNCTKEY_RELEASE 0x07    //Function key release
-#define SUBTYPE_KEYBOARD_OTHERKEY_PRESS 0x08      //Other keys press
-#define SUBTYPE_KEYBOARD_OTHERKEY_RELEASE 0x09    //Other keys release
-#define SUBTYPE_KEYBOARD_NUMPAD_PRESS 0x0A        //Numpad numeric press
-#define SUBTYPE_KEYBOARD_NUMPAD_RELEASE 0x0B      //Numpad numeric release
-#define SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL 0xFD  //Ctrl + Alt + Del
-#define SUBTYPE_KEYBOARD_SPECIAL_RESET 0xFE       //Reset all keypress state
-#define SUBTYPE_KEYBOARD_SPECIAL_RESERVED 0xFF    //Reserved
+#define SUBTYPE_KEYBOARD_ASCII_WRITE 0x01           // Write ASCII characters (32-127)
+#define SUBTYPE_KEYBOARD_ASCII_PRESS 0x02           // Press a key (ASCII 32-127)
+#define SUBTYPE_KEYBOARD_ASCII_RELEASE 0x03         // Release a key (ASCII 32-127)
+#define SUBTYPE_KEYBOARD_MODIFIER_PRESS 0x04        // Modifier key write (bit flags)
+#define SUBTYPE_KEYBOARD_MODIFIER_RELEASE 0x05      // Modifier key press (bit flags)
+#define SUBTYPE_KEYBOARD_FUNCTKEY_PRESS 0x06        //Function key press
+#define SUBTYPE_KEYBOARD_FUNCTKEY_RELEASE 0x07      //Function key release
+#define SUBTYPE_KEYBOARD_OTHERKEY_PRESS 0x08        //Other keys press
+#define SUBTYPE_KEYBOARD_OTHERKEY_RELEASE 0x09      //Other keys release
+#define SUBTYPE_KEYBOARD_NUMPAD_PRESS 0x0A          //Numpad numeric press
+#define SUBTYPE_KEYBOARD_NUMPAD_RELEASE 0x0B        //Numpad numeric release
+#define SUBTYPE_KEYBOARD_SPECIAL_PAUSE 0xF9         //Pause | Break
+#define SUBTYPE_KEYBOARD_SPECIAL_PRINT_SCREEN 0xFA  //Print Screen (hardware offload)
+#define SUBTYPE_KEYBOARD_SPECIAL_SCROLL_LOCK 0xFB   //Scroll Lock (hardware offload)
+#define SUBTYPE_KEYBOARD_SPECIAL_NUMLOCK 0xFC       //Toggle NumLock (hardware offload)
+#define SUBTYPE_KEYBOARD_SPECIAL_CTRLALTDEL 0xFD    //Ctrl + Alt + Del (hardware offload)
+#define SUBTYPE_KEYBOARD_SPECIAL_RESET 0xFE         //Reset all keypress state
+#define SUBTYPE_KEYBOARD_SPECIAL_RESERVED 0xFF      //Reserved
 
 /* Modifier Keys IDs */
 #define PAYLOAD_KEY_LEFT_CTRL 0x00