From 4cd9c3d77ed0741db7852f82cc39b61a60f06492 Mon Sep 17 00:00:00 2001 From: Alexander Barker Date: Tue, 11 Jul 2023 22:45:11 -0700 Subject: [PATCH] Distinguish emulated input and user input (Bug #110) --- src/windows/dispatch_event.c | 16 ++++++++-------- src/x11/dispatch_event.c | 20 ++++++++++---------- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/src/windows/dispatch_event.c b/src/windows/dispatch_event.c index 8240a98a..23fdbe35 100644 --- a/src/windows/dispatch_event.c +++ b/src/windows/dispatch_event.c @@ -150,7 +150,7 @@ bool dispatch_key_press(KBDLLHOOKSTRUCT *kbhook) { // Populate key pressed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = kbhook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_KEY_PRESSED; uio_event.mask = get_modifiers(); @@ -177,7 +177,7 @@ bool dispatch_key_press(KBDLLHOOKSTRUCT *kbhook) { for (unsigned int i = 0; i < count; i++) { // Populate key typed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = kbhook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_KEY_TYPED; uio_event.mask = get_modifiers(); @@ -222,7 +222,7 @@ bool dispatch_key_release(KBDLLHOOKSTRUCT *kbhook) { // Populate key pressed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = kbhook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_KEY_RELEASED; uio_event.mask = get_modifiers(); @@ -275,7 +275,7 @@ bool dispatch_button_press(MSLLHOOKSTRUCT *mshook, uint16_t button) { // Populate mouse pressed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = mshook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_PRESSED; uio_event.mask = get_modifiers(); @@ -308,7 +308,7 @@ bool dispatch_button_release(MSLLHOOKSTRUCT *mshook, uint16_t button) { // Populate mouse released event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = kbhook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_RELEASED; uio_event.mask = get_modifiers(); @@ -332,7 +332,7 @@ bool dispatch_button_release(MSLLHOOKSTRUCT *mshook, uint16_t button) { if (!consumed && last_click.x == mshook->pt.x && last_click.y == mshook->pt.y) { // Populate mouse clicked event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = mshook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_CLICKED; uio_event.mask = get_modifiers(); @@ -380,7 +380,7 @@ bool dispatch_mouse_move(MSLLHOOKSTRUCT *mshook) { // Populate mouse move event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = mshook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.mask = get_modifiers(); @@ -427,7 +427,7 @@ bool dispatch_mouse_wheel(MSLLHOOKSTRUCT *mshook, uint8_t direction) { // Populate mouse wheel event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = mshook->flags & LLKHF_INJECTED ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_WHEEL; uio_event.mask = get_modifiers(); diff --git a/src/x11/dispatch_event.c b/src/x11/dispatch_event.c index f1550893..07864ad0 100644 --- a/src/x11/dispatch_event.c +++ b/src/x11/dispatch_event.c @@ -72,7 +72,7 @@ void dispatch_hook_enabled(XAnyEvent * const x_event) { // Populate the hook start event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_HOOK_ENABLED; uio_event.mask = 0x00; @@ -84,7 +84,7 @@ void dispatch_hook_enabled(XAnyEvent * const x_event) { void dispatch_hook_disabled(XAnyEvent * const x_event) { // Populate the hook stop event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_HOOK_DISABLED; uio_event.mask = 0x00; @@ -124,7 +124,7 @@ void dispatch_key_press(XKeyPressedEvent * const x_event) { // Populate key pressed event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_KEY_PRESSED; uio_event.mask = get_modifiers(); @@ -145,7 +145,7 @@ void dispatch_key_press(XKeyPressedEvent * const x_event) { for (unsigned int i = 0; i < count; i++) { // Populate key typed event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_KEY_TYPED; uio_event.mask = get_modifiers(); @@ -189,7 +189,7 @@ void dispatch_key_release(XKeyReleasedEvent * const x_event) { // Populate key released event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_KEY_RELEASED; uio_event.mask = get_modifiers(); @@ -213,7 +213,7 @@ static void dispatch_mouse_wheel_rotated(XButtonEvent * const x_event) { // Populate mouse wheel event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_WHEEL; uio_event.mask = get_modifiers(); @@ -327,7 +327,7 @@ static void dispatch_mouse_button_pressed(XButtonPressedEvent * const x_event) { // Populate mouse pressed event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_PRESSED; uio_event.mask = get_modifiers(); @@ -416,7 +416,7 @@ static void dispatch_mouse_button_released(XButtonReleasedEvent * const x_event) // Populate mouse released event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_RELEASED; uio_event.mask = get_modifiers(); @@ -451,7 +451,7 @@ static void dispatch_mouse_button_released(XButtonReleasedEvent * const x_event) static void dispatch_mouse_button_clicked(XButtonEvent * const x_event) { // Populate mouse clicked event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_CLICKED; uio_event.mask = get_modifiers(); @@ -518,7 +518,7 @@ void dispatch_mouse_move(XMotionEvent * const x_event) { // Populate mouse move event. uio_event.time = x_event->serial; - uio_event.reserved = 0x00; + uio_event.reserved = x_event->send_event ? 0x02 : 0x00; uio_event.mask = get_modifiers();