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/darwin/dispatch_event.c b/src/darwin/dispatch_event.c index cc492907..a6a09714 100644 --- a/src/darwin/dispatch_event.c +++ b/src/darwin/dispatch_event.c @@ -116,7 +116,7 @@ bool dispatch_key_press(uint64_t timestamp, CGEventRef event_ref) { // Populate key pressed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_KEY_PRESSED; uio_event.mask = get_modifiers(); @@ -141,7 +141,7 @@ bool dispatch_key_press(uint64_t timestamp, CGEventRef event_ref) { for (unsigned int i = 0; i < length; i++) { // Populate key typed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_KEY_TYPED; uio_event.mask = get_modifiers(); @@ -171,7 +171,7 @@ bool dispatch_key_release(uint64_t timestamp, CGEventRef event_ref) { // Populate key released event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_KEY_RELEASED; uio_event.mask = get_modifiers(); @@ -469,7 +469,7 @@ bool dispatch_button_press(uint64_t timestamp, CGEventRef event_ref, uint16_t bu // Populate mouse pressed event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_PRESSED; uio_event.mask = get_modifiers(); @@ -498,7 +498,7 @@ bool dispatch_button_release(uint64_t timestamp, CGEventRef event_ref, uint16_t // Populate mouse released event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_RELEASED; uio_event.mask = get_modifiers(); @@ -521,7 +521,7 @@ bool dispatch_button_release(uint64_t timestamp, CGEventRef event_ref, uint16_t if (uio_event.reserved ^ 0x01 && !is_mouse_dragged()) { // Populate mouse clicked event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_CLICKED; uio_event.mask = get_modifiers(); @@ -562,7 +562,7 @@ bool dispatch_mouse_move(uint64_t timestamp, CGEventRef event_ref) { // Populate mouse motion event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; if (is_mouse_dragged()) { uio_event.type = EVENT_MOUSE_DRAGGED; @@ -603,7 +603,7 @@ bool dispatch_mouse_wheel(uint64_t timestamp, CGEventRef event_ref) { // Populate mouse wheel event. uio_event.time = timestamp; - uio_event.reserved = 0x00; + uio_event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00; uio_event.type = EVENT_MOUSE_WHEEL; uio_event.mask = get_modifiers(); 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..275e0ef6 100644 --- a/src/x11/dispatch_event.c +++ b/src/x11/dispatch_event.c @@ -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();