Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Distinguish mouse and touch events #195

Draft
wants to merge 2 commits into
base: 1.3
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions include/uiohook.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,7 @@ typedef void (*dispatcher_t)(uiohook_event * const, void *);
#define MASK_CAPS_LOCK 1 << 14
#define MASK_SCROLL_LOCK 1 << 15

#define MASK_TOUCHED 1 << 29
#define MASK_EMULATED 1 << 30
#define MASK_CONSUMED 1 << 31
/* End Virtual Modifier Masks */
Expand Down
12 changes: 12 additions & 0 deletions src/windows/dispatch_event.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
#include "input_helper.h"
#include "logger.h"

// Flag to recognize touch events: https://stackoverflow.com/questions/45473673/how-to-distinguish-touch-vs-mouse-event-from-setwindowshookex-in-c-sharp
static ULONG_PTR TOUCH_FLAG = 0xFF515700;

// Virtual event pointer.
static uiohook_event uio_event;

Expand Down Expand Up @@ -246,6 +249,9 @@ bool dispatch_button_press(uint64_t timestamp, MSLLHOOKSTRUCT *mshook, uint16_t
if (mshook->flags & (LLMHF_INJECTED | LLMHF_LOWER_IL_INJECTED)) {
uio_event.mask |= MASK_EMULATED;
}
if((mshook->dwExtraInfo & TOUCH_FLAG) == TOUCH_FLAG) {
uio_event.mask |= MASK_TOUCHED;
}

uio_event.data.mouse.button = button;
uio_event.data.mouse.clicks = click_count;
Expand Down Expand Up @@ -275,6 +281,9 @@ bool dispatch_button_release(uint64_t timestamp, MSLLHOOKSTRUCT *mshook, uint16_
if (mshook->flags & (LLMHF_INJECTED | LLMHF_LOWER_IL_INJECTED)) {
uio_event.mask |= MASK_EMULATED;
}
if((mshook->dwExtraInfo & TOUCH_FLAG) == TOUCH_FLAG) {
uio_event.mask |= MASK_TOUCHED;
}

uio_event.data.mouse.button = button;
uio_event.data.mouse.clicks = click_count;
Expand Down Expand Up @@ -343,6 +352,9 @@ bool dispatch_mouse_move(uint64_t timestamp, MSLLHOOKSTRUCT *mshook) {
if (mshook->flags & (LLMHF_INJECTED | LLMHF_LOWER_IL_INJECTED)) {
uio_event.mask |= MASK_EMULATED;
}
if((mshook->dwExtraInfo & TOUCH_FLAG) == TOUCH_FLAG) {
uio_event.mask |= MASK_TOUCHED;
}

// Check the modifier mask range for MASK_BUTTON1 - 5.
bool mouse_dragged = uio_event.mask & (MASK_BUTTON1 | MASK_BUTTON2 | MASK_BUTTON3 | MASK_BUTTON4 | MASK_BUTTON5);
Expand Down