mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-12 09:10:30 +08:00
refactoring
This commit is contained in:
parent
58f60bb49f
commit
a9c844acb4
@ -82,7 +82,7 @@ uint8_t cmdMouseButtonEvent(const uint8_t *buffer) { // 2 bytes
|
|||||||
# define MOUSE_PAIR(_state, _button) \
|
# define MOUSE_PAIR(_state, _button) \
|
||||||
_state & PROTO_CMD_MOUSE_BUTTON_##_button##_SELECT, \
|
_state & PROTO_CMD_MOUSE_BUTTON_##_button##_SELECT, \
|
||||||
_state & PROTO_CMD_MOUSE_BUTTON_##_button##_STATE
|
_state & PROTO_CMD_MOUSE_BUTTON_##_button##_STATE
|
||||||
hid_mouse.sendMouseButtons(
|
hid_mouse.sendButtons(
|
||||||
MOUSE_PAIR(main_state, LEFT),
|
MOUSE_PAIR(main_state, LEFT),
|
||||||
MOUSE_PAIR(main_state, RIGHT),
|
MOUSE_PAIR(main_state, RIGHT),
|
||||||
MOUSE_PAIR(main_state, MIDDLE),
|
MOUSE_PAIR(main_state, MIDDLE),
|
||||||
@ -104,14 +104,14 @@ uint8_t cmdMouseMoveEvent(const uint8_t *buffer) { // 4 bytes
|
|||||||
y |= (int)buffer[3];
|
y |= (int)buffer[3];
|
||||||
y = (y + 32768) / 2; // See /kvmd/apps/otg/hid/keyboard.py for details
|
y = (y + 32768) / 2; // See /kvmd/apps/otg/hid/keyboard.py for details
|
||||||
|
|
||||||
hid_mouse.sendMouseMove(x, y);
|
hid_mouse.sendMove(x, y);
|
||||||
# endif
|
# endif
|
||||||
return PROTO_RESP_OK;
|
return PROTO_RESP_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
|
uint8_t cmdMouseWheelEvent(const uint8_t *buffer) { // 2 bytes
|
||||||
# ifdef HID_USB_MOUSE
|
# ifdef HID_USB_MOUSE
|
||||||
hid_mouse.sendMouseWheel(buffer[1]); // Y only, X is not supported
|
hid_mouse.sendWheel(buffer[1]); // Y only, X is not supported
|
||||||
# endif
|
# endif
|
||||||
return PROTO_RESP_OK;
|
return PROTO_RESP_OK;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -71,31 +71,31 @@ class UsbHidMouse {
|
|||||||
SingleAbsoluteMouse.releaseAll();
|
SingleAbsoluteMouse.releaseAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMouseButtons(
|
void sendButtons(
|
||||||
bool left_select, bool left_state,
|
bool left_select, bool left_state,
|
||||||
bool right_select, bool right_state,
|
bool right_select, bool right_state,
|
||||||
bool middle_select, bool middle_state,
|
bool middle_select, bool middle_state,
|
||||||
bool up_select, bool up_state,
|
bool up_select, bool up_state,
|
||||||
bool down_select, bool down_state
|
bool down_select, bool down_state
|
||||||
) {
|
) {
|
||||||
if (left_select) _sendMouseButton(MOUSE_LEFT, left_state);
|
if (left_select) _sendButton(MOUSE_LEFT, left_state);
|
||||||
if (right_select) _sendMouseButton(MOUSE_RIGHT, right_state);
|
if (right_select) _sendButton(MOUSE_RIGHT, right_state);
|
||||||
if (middle_select) _sendMouseButton(MOUSE_MIDDLE, middle_state);
|
if (middle_select) _sendButton(MOUSE_MIDDLE, middle_state);
|
||||||
if (up_select) _sendMouseButton(MOUSE_PREV, up_state);
|
if (up_select) _sendButton(MOUSE_PREV, up_state);
|
||||||
if (down_select) _sendMouseButton(MOUSE_NEXT, down_state);
|
if (down_select) _sendButton(MOUSE_NEXT, down_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMouseMove(int x, int y) {
|
void sendMove(int x, int y) {
|
||||||
SingleAbsoluteMouse.moveTo(x, y);
|
SingleAbsoluteMouse.moveTo(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sendMouseWheel(int delta_y) {
|
void sendWheel(int delta_y) {
|
||||||
// delta_x is not supported by hid-project now
|
// delta_x is not supported by hid-project now
|
||||||
SingleAbsoluteMouse.move(0, 0, delta_y);
|
SingleAbsoluteMouse.move(0, 0, delta_y);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _sendMouseButton(uint8_t button, bool state) {
|
void _sendButton(uint8_t button, bool state) {
|
||||||
if (state) SingleAbsoluteMouse.press(button);
|
if (state) SingleAbsoluteMouse.press(button);
|
||||||
else SingleAbsoluteMouse.release(button);
|
else SingleAbsoluteMouse.release(button);
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user