mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-01-29 00:51:53 +08:00
serial hid: added middle button
This commit is contained in:
@@ -49,10 +49,12 @@
|
|||||||
#define PROTO_CMD_MOUSE_BUTTON_EVENT 0x13
|
#define PROTO_CMD_MOUSE_BUTTON_EVENT 0x13
|
||||||
#define PROTO_CMD_MOUSE_WHEEL_EVENT 0x14
|
#define PROTO_CMD_MOUSE_WHEEL_EVENT 0x14
|
||||||
// -----------------------------------------
|
// -----------------------------------------
|
||||||
#define PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT 0b10000000
|
#define PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT 0b10000000
|
||||||
#define PROTO_CMD_MOUSE_BUTTON_LEFT_STATE 0b00001000
|
#define PROTO_CMD_MOUSE_BUTTON_LEFT_STATE 0b00001000
|
||||||
#define PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT 0b01000000
|
#define PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT 0b01000000
|
||||||
#define PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE 0b00000100
|
#define PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE 0b00000100
|
||||||
|
#define PROTO_CMD_MOUSE_BUTTON_MIDDLE_SELECT 0b00100000
|
||||||
|
#define PROTO_CMD_MOUSE_BUTTON_MIDDLE_STATE 0b00000010
|
||||||
|
|
||||||
|
|
||||||
// -----------------------------------------------------------------------------
|
// -----------------------------------------------------------------------------
|
||||||
@@ -86,21 +88,21 @@ INLINE void cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
|
|||||||
INLINE void cmdMouseButtonEvent(const uint8_t *buffer) { // 1 byte
|
INLINE void cmdMouseButtonEvent(const uint8_t *buffer) { // 1 byte
|
||||||
uint8_t state = buffer[0];
|
uint8_t state = buffer[0];
|
||||||
|
|
||||||
if (state & PROTO_CMD_MOUSE_BUTTON_LEFT_SELECT) {
|
# define PROCESS_BUTTON(name) { \
|
||||||
if (state & PROTO_CMD_MOUSE_BUTTON_LEFT_STATE) {
|
if (state & PROTO_CMD_MOUSE_BUTTON_##name##_SELECT) { \
|
||||||
SingleAbsoluteMouse.press(MOUSE_LEFT);
|
if (state & PROTO_CMD_MOUSE_BUTTON_##name##_STATE) { \
|
||||||
} else {
|
SingleAbsoluteMouse.press(MOUSE_##name); \
|
||||||
SingleAbsoluteMouse.release(MOUSE_LEFT);
|
} else { \
|
||||||
|
SingleAbsoluteMouse.release(MOUSE_##name); \
|
||||||
|
} \
|
||||||
|
} \
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (state & PROTO_CMD_MOUSE_BUTTON_RIGHT_SELECT) {
|
PROCESS_BUTTON(LEFT);
|
||||||
if (state & PROTO_CMD_MOUSE_BUTTON_RIGHT_STATE) {
|
PROCESS_BUTTON(RIGHT);
|
||||||
SingleAbsoluteMouse.press(MOUSE_RIGHT);
|
PROCESS_BUTTON(MIDDLE);
|
||||||
} else {
|
|
||||||
SingleAbsoluteMouse.release(MOUSE_RIGHT);
|
# undef PROCESS_BUTTON
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
INLINE void cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
|
INLINE void cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ class _MouseMoveEvent(_IntEvent):
|
|||||||
@dataclasses.dataclass(frozen=True)
|
@dataclasses.dataclass(frozen=True)
|
||||||
class _MouseButtonEvent(_BoolEvent):
|
class _MouseButtonEvent(_BoolEvent):
|
||||||
def __post_init__(self) -> None:
|
def __post_init__(self) -> None:
|
||||||
assert self.name in ["left", "right"]
|
assert self.name in ["left", "right", "middle"]
|
||||||
|
|
||||||
def make_command(self) -> bytes:
|
def make_command(self) -> bytes:
|
||||||
code = 0
|
code = 0
|
||||||
@@ -110,6 +110,8 @@ class _MouseButtonEvent(_BoolEvent):
|
|||||||
code = (0b10000000 | (0b00001000 if self.state else 0))
|
code = (0b10000000 | (0b00001000 if self.state else 0))
|
||||||
elif self.name == "right":
|
elif self.name == "right":
|
||||||
code = (0b01000000 | (0b00000100 if self.state else 0))
|
code = (0b01000000 | (0b00000100 if self.state else 0))
|
||||||
|
elif self.name == "middle":
|
||||||
|
code = (0b00100000 | (0b00000010 if self.state else 0))
|
||||||
assert code, self
|
assert code, self
|
||||||
return b"\x13" + bytes([code]) + b"\x00\x00\x00"
|
return b"\x13" + bytes([code]) + b"\x00\x00\x00"
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user