Skip to content

Commit

Permalink
Distinguish emulated input and user input (Bug #110)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed Nov 28, 2023
1 parent f9a346c commit 4c24564
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions demo/demo_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 8 additions & 8 deletions src/darwin/dispatch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions src/windows/dispatch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();

Expand Down Expand Up @@ -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();
Expand Down
16 changes: 8 additions & 8 deletions src/x11/dispatch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();

Expand Down

0 comments on commit 4c24564

Please sign in to comment.