Skip to content

Commit

Permalink
update to 1.3 branch
Browse files Browse the repository at this point in the history
  • Loading branch information
SnosMe committed Jun 29, 2023
1 parent de2786c commit 1bf5ecc
Show file tree
Hide file tree
Showing 7 changed files with 142 additions and 144 deletions.
3 changes: 3 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
'libuiohook/src/windows/input_helper.c',
'libuiohook/src/windows/input_hook.c',
'libuiohook/src/windows/post_event.c',
'libuiohook/src/windows/dispatch_event.c',
'libuiohook/src/windows/system_properties.c'
],
'include_dirs': [
Expand All @@ -49,6 +50,7 @@
'libuiohook/src/x11/input_helper.c',
'libuiohook/src/x11/input_hook.c',
'libuiohook/src/x11/post_event.c',
'libuiohook/src/x11/dispatch_event.c',
'libuiohook/src/x11/system_properties.c'
],
'include_dirs': [
Expand All @@ -73,6 +75,7 @@
"libuiohook/src/darwin/input_helper.c",
"libuiohook/src/darwin/input_hook.c",
"libuiohook/src/darwin/post_event.c",
"libuiohook/src/darwin/dispatch_event.c",
"libuiohook/src/darwin/system_properties.c"
],
'include_dirs': [
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "uiohook-napi",
"version": "1.5.1",
"version": "2.0.0",
"author": {
"name": "Alexander Drozdov"
},
Expand Down
246 changes: 123 additions & 123 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,129 +71,129 @@ export enum WheelDirection {
}

export const UiohookKey = {
Backspace: 0x000E,
Tab: 0x000F,
Enter: 0x001C,
CapsLock: 0x003A,
Escape: 0x0001,
Space: 0x0039,
PageUp: 0x0E49,
PageDown: 0x0E51,
End: 0x0E4F,
Home: 0x0E47,
ArrowLeft: 0xE04B,
ArrowUp: 0xE048,
ArrowRight: 0xE04D,
ArrowDown: 0xE050,
Insert: 0x0E52,
Delete: 0x0E53,
0: 0x000B,
1: 0x0002,
2: 0x0003,
3: 0x0004,
4: 0x0005,
5: 0x0006,
6: 0x0007,
7: 0x0008,
8: 0x0009,
9: 0x000A,
A: 0x001E,
B: 0x0030,
C: 0x002E,
D: 0x0020,
E: 0x0012,
F: 0x0021,
G: 0x0022,
H: 0x0023,
I: 0x0017,
J: 0x0024,
K: 0x0025,
L: 0x0026,
M: 0x0032,
N: 0x0031,
O: 0x0018,
P: 0x0019,
Q: 0x0010,
R: 0x0013,
S: 0x001F,
T: 0x0014,
U: 0x0016,
V: 0x002F,
W: 0x0011,
X: 0x002D,
Y: 0x0015,
Z: 0x002C,
Numpad0: 0x0052,
Numpad1: 0x004F,
Numpad2: 0x0050,
Numpad3: 0x0051,
Numpad4: 0x004B,
Numpad5: 0x004C,
Numpad6: 0x004D,
Numpad7: 0x0047,
Numpad8: 0x0048,
Numpad9: 0x0049,
NumpadMultiply: 0x0037,
NumpadAdd: 0x004E,
NumpadSubtract: 0x004A,
NumpadDecimal: 0x0053,
NumpadDivide: 0x0E35,
NumpadEnd: 0xEE00 | 0x004F,
NumpadArrowDown: 0xEE00 | 0x0050,
NumpadPageDown: 0xEE00 | 0x0051,
NumpadArrowLeft: 0xEE00 | 0x004B,
NumpadArrowRight: 0xEE00 | 0x004D,
NumpadHome: 0xEE00 | 0x0047,
NumpadArrowUp: 0xEE00 | 0x0048,
NumpadPageUp: 0xEE00 | 0x0049,
NumpadInsert: 0xEE00 | 0x0052,
NumpadDelete: 0xEE00 | 0x0053,
F1: 0x003B,
F2: 0x003C,
F3: 0x003D,
F4: 0x003E,
F5: 0x003F,
F6: 0x0040,
F7: 0x0041,
F8: 0x0042,
F9: 0x0043,
F10: 0x0044,
F11: 0x0057,
F12: 0x0058,
F13: 0x005B,
F14: 0x005C,
F15: 0x005D,
F16: 0x0063,
F17: 0x0064,
F18: 0x0065,
F19: 0x0066,
F20: 0x0067,
F21: 0x0068,
F22: 0x0069,
F23: 0x006A,
F24: 0x006B,
Semicolon: 0x0027,
Equal: 0x000D,
Comma: 0x0033,
Minus: 0x000C,
Period: 0x0034,
Slash: 0x0035,
Backquote: 0x0029,
BracketLeft: 0x001A,
Backslash: 0x002B,
BracketRight: 0x001B,
Quote: 0x0028,
Ctrl: 0x001D, // Left
CtrlRight: 0x0E1D,
Alt: 0x0038, // Left
AltRight: 0x0E38,
Shift: 0x002A, // Left
ShiftRight: 0x0036,
Meta: 0x0E5B,
MetaRight: 0x0E5C,
NumLock: 0x0045,
ScrollLock: 0x0046,
PrintScreen: 0x0E37,
Backspace: 0x0008,
Tab: 0x0009,
Enter: 0x000A,
CapsLock: 0x0014,
Escape: 0x001B,
Space: 0x0020,
PageUp: 0x0021,
PageDown: 0x0022,
End: 0x0023,
Home: 0x0024,
ArrowLeft: 0x0025,
ArrowUp: 0x0026,
ArrowRight: 0x0027,
ArrowDown: 0x0028,
Insert: 0x009B,
Delete: 0x007F,
0: 0x0030,
1: 0x0031,
2: 0x0032,
3: 0x0033,
4: 0x0034,
5: 0x0035,
6: 0x0036,
7: 0x0037,
8: 0x0038,
9: 0x0039,
A: 0x0041,
B: 0x0042,
C: 0x0043,
D: 0x0044,
E: 0x0045,
F: 0x0046,
G: 0x0047,
H: 0x0048,
I: 0x0049,
J: 0x004A,
K: 0x004B,
L: 0x004C,
M: 0x004D,
N: 0x004E,
O: 0x004F,
P: 0x0050,
Q: 0x0051,
R: 0x0052,
S: 0x0053,
T: 0x0054,
U: 0x0055,
V: 0x0056,
W: 0x0057,
X: 0x0058,
Y: 0x0059,
Z: 0x005A,
Numpad0: 0x0060,
Numpad1: 0x0061,
Numpad2: 0x0062,
Numpad3: 0x0063,
Numpad4: 0x0064,
Numpad5: 0x0065,
Numpad6: 0x0066,
Numpad7: 0x0067,
Numpad8: 0x0068,
Numpad9: 0x0069,
NumpadMultiply: 0x006A,
NumpadAdd: 0x006B,
NumpadSubtract: 0x006D,
NumpadDecimal: 0x006C,
NumpadDivide: 0x006F,
NumpadEnd: 0xEE00 | 0x0061,
NumpadArrowDown: 0xEE00 | 0x0062,
NumpadPageDown: 0xEE00 | 0x0063,
NumpadArrowLeft: 0xEE00 | 0x0064,
NumpadArrowRight: 0xEE00 | 0x0066,
NumpadHome: 0xEE00 | 0x0067,
NumpadArrowUp: 0xEE00 | 0x0068,
NumpadPageUp: 0xEE00 | 0x0069,
NumpadInsert: 0xEE00 | 0x0060,
NumpadDelete: 0xEE00 | 0x006C,
F1: 0x0070,
F2: 0x0071,
F3: 0x0072,
F4: 0x0073,
F5: 0x0074,
F6: 0x0075,
F7: 0x0076,
F8: 0x0077,
F9: 0x0078,
F10: 0x0079,
F11: 0x007A,
F12: 0x007B,
F13: 0xF000,
F14: 0xF001,
F15: 0xF002,
F16: 0xF003,
F17: 0xF004,
F18: 0xF005,
F19: 0xF006,
F20: 0xF007,
F21: 0xF008,
F22: 0xF009,
F23: 0xF00A,
F24: 0xF00B,
Semicolon: 0x003B,
Equal: 0x003D,
Comma: 0x002C,
Minus: 0x002D,
Period: 0x002E,
Slash: 0x002F,
Backquote: 0x00C0,
BracketLeft: 0x005B,
Backslash: 0x005D,
BracketRight: 0x005C,
Quote: 0x00DE,
Ctrl: 0xA011, // Left
CtrlRight: 0xB011,
Alt: 0xA012, // Left
AltRight: 0xB012,
Shift: 0xA010, // Left
ShiftRight: 0xB010,
Meta: 0xA09D,
MetaRight: 0xB09D,
NumLock: 0x0090,
ScrollLock: 0x0091,
PrintScreen: 0x009A,
} as const

declare interface UiohookNapi {
Expand Down
13 changes: 4 additions & 9 deletions src/lib/addon.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
static napi_threadsafe_function threadsafe_fn = NULL;
static bool is_worker_running = false;

void dispatch_proc(uiohook_event* const event) {
void dispatch_proc(uiohook_event* const event, void* userdata) {
if (threadsafe_fn == NULL) return;

uiohook_event* copied_event = malloc(sizeof(uiohook_event));
Expand Down Expand Up @@ -117,12 +117,8 @@ napi_value uiohook_to_js_event(napi_env env, uiohook_event* event) {
status = napi_create_int32(env, event->data.wheel.y, &e_y);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_create_int32");

napi_value e_clicks;
status = napi_create_uint32(env, event->data.wheel.clicks, &e_clicks);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_create_uint32");

napi_value e_amount;
status = napi_create_uint32(env, event->data.wheel.amount, &e_amount);
napi_value e_delta;
status = napi_create_uint32(env, event->data.wheel.delta, &e_delta);
NAPI_FATAL_IF_FAILED(status, "uiohook_to_js_event", "napi_create_uint32");

napi_value e_direction;
Expand All @@ -142,8 +138,7 @@ napi_value uiohook_to_js_event(napi_env env, uiohook_event* event) {
{ "shiftKey", NULL, NULL, NULL, NULL, e_shiftKey, napi_enumerable, NULL },
{ "x", NULL, NULL, NULL, NULL, e_x, napi_enumerable, NULL },
{ "y", NULL, NULL, NULL, NULL, e_y, napi_enumerable, NULL },
{ "clicks", NULL, NULL, NULL, NULL, e_clicks, napi_enumerable, NULL },
{ "amount", NULL, NULL, NULL, NULL, e_amount, napi_enumerable, NULL },
{ "delta", NULL, NULL, NULL, NULL, e_delta, napi_enumerable, NULL },
{ "direction", NULL, NULL, NULL, NULL, e_direction, napi_enumerable, NULL },
{ "rotation", NULL, NULL, NULL, NULL, e_rotation, napi_enumerable, NULL },
};
Expand Down
8 changes: 4 additions & 4 deletions src/lib/uiohook_worker.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ bool logger_proc(unsigned int level, const char* format, ...) {
// Furthermore, some operating systems may choose to disable your hook if it
// takes to long to process. If you need to do any extended processing, please
// do so by copying the event to your own queued dispatch thread.
void worker_dispatch_proc(uiohook_event* const event) {
void worker_dispatch_proc(uiohook_event* const event, void* userdata) {
switch (event->type) {
case EVENT_HOOK_ENABLED:
// Lock the running mutex so we know if the hook is enabled.
Expand Down Expand Up @@ -72,7 +72,7 @@ void worker_dispatch_proc(uiohook_event* const event) {
case EVENT_MOUSE_MOVED:
case EVENT_MOUSE_DRAGGED:
case EVENT_MOUSE_WHEEL: {
user_dispatcher(event);
user_dispatcher(event, userdata);
break;
}

Expand Down Expand Up @@ -164,10 +164,10 @@ int uiohook_worker_start(dispatcher_t dispatch_proc) {
uv_cond_init(&hook_control_cond);

// Set the logger callback for library output.
hook_set_logger_proc(logger_proc);
hook_set_logger_proc(logger_proc, NULL);

// Set the event callback for uiohook events.
hook_set_dispatch_proc(worker_dispatch_proc);
hook_set_dispatch_proc(worker_dispatch_proc, NULL);

user_dispatcher = dispatch_proc;

Expand Down
12 changes: 6 additions & 6 deletions src/libuiohook.patch
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
diff --git a/src/windows/input_helper.c b/src/windows/input_helper.c
index e690021..4b7cff1 100644
index 2a8e6ae..23f7975 100644
--- a/src/windows/input_helper.c
+++ b/src/windows/input_helper.c
@@ -298,7 +298,7 @@ unsigned short keycode_to_scancode(DWORD vk_code, DWORD flags) {
@@ -301,7 +301,7 @@ unsigned short keycode_to_scancode(DWORD vk_code, DWORD flags) {
if (vk_code < sizeof(keycode_scancode_table) / sizeof(keycode_scancode_table[0])) {
scancode = keycode_scancode_table[vk_code][0];

Expand All @@ -12,10 +12,10 @@ index e690021..4b7cff1 100644
__FUNCTION__, __LINE__, vk_code);

diff --git a/src/windows/input_hook.c b/src/windows/input_hook.c
index db1e79e..e4fd59a 100644
index 10e8f5b..bcfc716 100644
--- a/src/windows/input_hook.c
+++ b/src/windows/input_hook.c
@@ -595,7 +595,7 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam)
@@ -236,7 +236,7 @@ LRESULT CALLBACK mouse_hook_event_proc(int nCode, WPARAM wParam, LPARAM lParam)
// Callback function that handles events.
void CALLBACK win_hook_event_proc(HWINEVENTHOOK hook, DWORD event, HWND hWnd, LONG idObject, LONG idChild, DWORD dwEventThread, DWORD dwmsEventTime) {
switch (event) {
Expand All @@ -24,7 +24,7 @@ index db1e79e..e4fd59a 100644
logger(LOG_LEVEL_DEBUG, "%s [%u]: Restarting Windows input hook on window event: %#X.\n",
__FUNCTION__, __LINE__, event);

@@ -662,7 +662,7 @@ UIOHOOK_API int hook_run() {
@@ -303,7 +303,7 @@ UIOHOOK_API int hook_run() {

// Create a window event hook to listen for capture change.
win_event_hhook = SetWinEventHook(
Expand All @@ -34,7 +34,7 @@ index db1e79e..e4fd59a 100644
win_hook_event_proc,
0, 0,
diff --git a/src/x11/input_hook.c b/src/x11/input_hook.c
index 15c9b9e..dc2f7b9 100644
index 9420421..f96bfc2 100644
--- a/src/x11/input_hook.c
+++ b/src/x11/input_hook.c
@@ -26,8 +26,11 @@
Expand Down

0 comments on commit 1bf5ecc

Please sign in to comment.