|
@@ -115,6 +115,30 @@ func appendKeyboardEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+// Append the mouse click event subtypes to the data
|
|
|
+func appendMouseClickEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
|
|
|
+ /* Mouse Click Subtypes */
|
|
|
+ isPress := cmd.EventSubType == FRONTEND_MOUSE_PRESS
|
|
|
+ if isPress {
|
|
|
+ //Mouse Button Press
|
|
|
+ data = append(data, 0x02)
|
|
|
+ } else {
|
|
|
+ //Mouse Button Release
|
|
|
+ data = append(data, 0x03)
|
|
|
+ }
|
|
|
+
|
|
|
+ if cmd.Data == FRONTEND_MOUSE_BTN_LEFT {
|
|
|
+ data = append(data, PAYLOAD_MOUSE_BTN_LEFT)
|
|
|
+ } else if cmd.Data == FRONTEND_MOUSE_BTN_MIDDLE {
|
|
|
+ data = append(data, PAYLOAD_MOUSE_BTN_MID)
|
|
|
+ } else if cmd.Data == FRONTEND_MOUSE_BTN_RIGHT {
|
|
|
+ data = append(data, PAYLOAD_MOUSE_BTN_RIGHT)
|
|
|
+ } else {
|
|
|
+ return nil, fmt.Errorf("invalid HID command subtype: %v", cmd.Data)
|
|
|
+ }
|
|
|
+ return data, nil
|
|
|
+}
|
|
|
+
|
|
|
// Append the mouse move event subtypes to the data
|
|
|
func appendMouseMoveEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
|
|
|
//The mouse move command requires x_pos, y_pos, x_sign, y_sign
|
|
@@ -148,16 +172,46 @@ func appendMouseMoveEventSubtypes(data []byte, cmd HIDCommand) ([]byte, error) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+// Append the mouse scroll event subtypes to the data
|
|
|
+// The sensitivityDivider is used to divide the scroll value to make it less sensitive
|
|
|
+func appendMouseScrollEventSubtypes(data []byte, cmd HIDCommand, sensitivityDivider int) ([]byte, error) {
|
|
|
+ //The mouse scroll command PosY contains the scroll value
|
|
|
+ //The scroll command require a direction byte and a scroll value byte
|
|
|
+ scrollValue := cmd.PosY
|
|
|
+ if scrollValue < 0 {
|
|
|
+ //Scroll up
|
|
|
+ scrollValue = -scrollValue
|
|
|
+ if scrollValue > 0x7F {
|
|
|
+ scrollValue = 0x7F
|
|
|
+ }
|
|
|
+ scrollValue /= sensitivityDivider
|
|
|
+ data = append(data, 0x00)
|
|
|
+ data = append(data, byte(scrollValue))
|
|
|
+ } else {
|
|
|
+ //SCroll down
|
|
|
+ if scrollValue > 0x7F {
|
|
|
+ scrollValue = 0x7F
|
|
|
+ }
|
|
|
+ scrollValue /= sensitivityDivider
|
|
|
+ data = append(data, 0x01)
|
|
|
+ data = append(data, byte(scrollValue))
|
|
|
+ }
|
|
|
+
|
|
|
+ return data, nil
|
|
|
+}
|
|
|
+
|
|
|
//Entry function for converting a HIDCommand to bytes that can be sent over the USBKVM device
|
|
|
func ConvHIDCommandToBytes(cmd HIDCommand) ([]byte, error) {
|
|
|
// Convert the HID command to bytes
|
|
|
var data []byte
|
|
|
if cmd.EventType == FRONTEND_OPR_TYPE_KEYBOARD_WRITE {
|
|
|
+ /* Keyboard Write Event */
|
|
|
data = []byte{OPR_TYPE_KEYBOARD_WRITE}
|
|
|
return appendKeyboardEventSubtypes(data, cmd)
|
|
|
} else if cmd.EventType == FRONTEND_OPR_TYPE_MOUSE_WRITE {
|
|
|
/* Mouse Write Event */
|
|
|
data = []byte{OPR_TYPE_MOUSE_WRITE}
|
|
|
+ return appendMouseClickEventSubtypes(data, cmd)
|
|
|
} else if cmd.EventType == FRONTEND_OPR_TYPE_MOUSE_MOVE {
|
|
|
/* Mouse Move Event */
|
|
|
data = []byte{OPR_TYPE_MOUSE_MOVE}
|
|
@@ -165,10 +219,8 @@ func ConvHIDCommandToBytes(cmd HIDCommand) ([]byte, error) {
|
|
|
} else if cmd.EventType == FRONTEND_OPR_TYPE_MOUSE_SCROLL {
|
|
|
/* Mouse Scroll Event */
|
|
|
data = []byte{OPR_TYPE_MOUSE_SCROLL}
|
|
|
-
|
|
|
- } else {
|
|
|
- return nil, fmt.Errorf("invalid HID command type: %s", cmd.EventType)
|
|
|
+ return appendMouseScrollEventSubtypes(data, cmd, 8)
|
|
|
}
|
|
|
|
|
|
- return data, nil
|
|
|
+ return nil, fmt.Errorf("invalid HID command type: %s", cmd.EventType)
|
|
|
}
|