Skip to content

Commit

Permalink
Distinguish emulated input and user input v1.2 backport (Bug #110)
Browse files Browse the repository at this point in the history
  • Loading branch information
kwhat committed Nov 28, 2023
1 parent 4d7b3fa commit f7ce07b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
16 changes: 8 additions & 8 deletions src/darwin/input_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ static inline void process_key_pressed(uint64_t timestamp, CGEventRef event_ref)

// Populate key pressed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_KEY_PRESSED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -328,7 +328,7 @@ static inline void process_key_pressed(uint64_t timestamp, CGEventRef event_ref)
for (unsigned int i = 0; i < tis_keycode_message->length; i++) {
// Populate key typed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_KEY_TYPED;
event.mask = get_modifiers();
Expand All @@ -352,7 +352,7 @@ static inline void process_key_released(uint64_t timestamp, CGEventRef event_ref

// Populate key released event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_KEY_RELEASED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -708,7 +708,7 @@ static inline void process_button_pressed(uint64_t timestamp, CGEventRef event_r

// Populate mouse pressed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_PRESSED;
event.mask = get_modifiers();
Expand All @@ -731,7 +731,7 @@ static inline void process_button_released(uint64_t timestamp, CGEventRef event_

// Populate mouse released event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_RELEASED;
event.mask = get_modifiers();
Expand All @@ -752,7 +752,7 @@ static inline void process_button_released(uint64_t timestamp, CGEventRef event_
if (event.reserved ^ 0x01 && mouse_dragged != true) {
// Populate mouse clicked event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_CLICKED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -787,7 +787,7 @@ static inline void process_mouse_moved(uint64_t timestamp, CGEventRef event_ref)

// Populate mouse motion event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

if (mouse_dragged) {
event.type = EVENT_MOUSE_DRAGGED;
Expand Down Expand Up @@ -824,7 +824,7 @@ static inline void process_mouse_wheel(uint64_t timestamp, CGEventRef event_ref)

// Populate mouse wheel event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = CGEventGetIntegerValueField(event_ref, kCGEventSourceUnixProcessID) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_WHEEL;
event.mask = get_modifiers();
Expand Down
16 changes: 8 additions & 8 deletions src/windows/input_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ static void process_key_pressed(KBDLLHOOKSTRUCT *kbhook) {

// Populate key pressed event.
event.time = kbhook->time;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_KEY_PRESSED;
event.mask = get_modifiers();
Expand All @@ -203,7 +203,7 @@ static void process_key_pressed(KBDLLHOOKSTRUCT *kbhook) {
for (unsigned int i = 0; i < count; i++) {
// Populate key typed event.
event.time = kbhook->time;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_KEY_TYPED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -237,7 +237,7 @@ static void process_key_released(KBDLLHOOKSTRUCT *kbhook) {

// Populate key pressed event.
event.time = kbhook->time;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_KEY_RELEASED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -313,7 +313,7 @@ static void process_button_pressed(MSLLHOOKSTRUCT *mshook, uint16_t button) {

// Populate mouse pressed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_PRESSED;
event.mask = get_modifiers();
Expand All @@ -335,7 +335,7 @@ static void process_button_pressed(MSLLHOOKSTRUCT *mshook, uint16_t button) {
static void process_button_released(MSLLHOOKSTRUCT *mshook, uint16_t button) {
// Populate mouse released event.
event.time = mshook->time;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_RELEASED;
event.mask = get_modifiers();
Expand All @@ -358,7 +358,7 @@ static void process_button_released(MSLLHOOKSTRUCT *mshook, uint16_t button) {
if (event.reserved ^ 0x01 && last_click.x == mshook->pt.x && last_click.y == mshook->pt.y) {
// Populate mouse clicked event.
event.time = mshook->time;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_CLICKED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -396,7 +396,7 @@ static void process_mouse_moved(MSLLHOOKSTRUCT *mshook) {

// Populate mouse move event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.mask = get_modifiers();

Expand Down Expand Up @@ -432,7 +432,7 @@ static void process_mouse_wheel(MSLLHOOKSTRUCT *mshook, uint8_t direction) {

// Populate mouse wheel event.
event.time = mshook->time;
event.reserved = 0x00;
event.reserved = kbhook->flags & (LLKHF_INJECTED | LLKHF_LOWER_IL_INJECTED) ? 0x02 : 0x00;

event.type = EVENT_MOUSE_WHEEL;
event.mask = get_modifiers();
Expand Down
16 changes: 8 additions & 8 deletions src/x11/input_hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {

// Populate key pressed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_KEY_PRESSED;
event.mask = get_modifiers();
Expand All @@ -365,7 +365,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {
for (unsigned int i = 0; i < count; i++) {
// Populate key typed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_KEY_TYPED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -439,7 +439,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {

// Populate key released event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_KEY_RELEASED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -473,7 +473,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {

// Populate mouse wheel event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_MOUSE_WHEEL;
event.mask = get_modifiers();
Expand Down Expand Up @@ -592,7 +592,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {

// Populate mouse pressed event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_MOUSE_PRESSED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -667,7 +667,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {

// Populate mouse released event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_MOUSE_RELEASED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -702,7 +702,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {
if (event.reserved ^ 0x01 && hook->input.mouse.is_dragged != true) {
// Populate mouse clicked event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.type = EVENT_MOUSE_CLICKED;
event.mask = get_modifiers();
Expand Down Expand Up @@ -748,7 +748,7 @@ void hook_event_proc(XPointer closeure, XRecordInterceptData *recorded_data) {

// Populate mouse move event.
event.time = timestamp;
event.reserved = 0x00;
event.reserved = x_event->send_event ? 0x02 : 0x00;

event.mask = get_modifiers();

Expand Down

0 comments on commit f7ce07b

Please sign in to comment.