From 53c6223945dbf36b167b94cb05e918d79ac1d887 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) --- demo/demo_hook.c | 4 ++-- src/windows/dispatch_event.c | 16 ++++++++-------- src/x11/dispatch_event.c | 20 ++++++++++---------- 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/demo/demo_hook.c b/demo/demo_hook.c index 128ebf68..5b8b7fd8 100644 --- a/demo/demo_hook.c +++ b/demo/demo_hook.c @@ -59,8 +59,8 @@ static void logger(unsigned int level, const char *format, ...) { void dispatch_proc(uiohook_event * const event, void *user_data) { char buffer[256] = { 0 }; size_t length = snprintf(buffer, sizeof(buffer), - "id=%i,when=%" PRIu64 ",mask=0x%X", - event->type, event->time, event->mask); + "id=%i,when=%" PRIu64 ",mask=0x%X, reserved=0x%X", + event->type, event->time, event->mask, event->reserved); switch (event->type) { case EVENT_KEY_PRESSED: diff --git a/src/windows/dispatch_event.c b/src/windows/dispatch_event.c index 8240a98a..46f59cce 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 | LLKHF_LOWER_IL_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 | LLKHF_LOWER_IL_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 | LLKHF_LOWER_IL_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 & (LLMHF_INJECTED | LLMHF_LOWER_IL_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 = mshook->flags & (LLMHF_INJECTED | LLMHF_LOWER_IL_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 & (LLMHF_INJECTED | LLMHF_LOWER_IL_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 & (LLMHF_INJECTED | LLMHF_LOWER_IL_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 & (LLMHF_INJECTED | LLMHF_LOWER_IL_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();