From 753751bb087595320fd5ffc2308bec8ba1b545ff Mon Sep 17 00:00:00 2001 From: Chevon Christie Date: Fri, 5 Feb 2021 10:40:48 -0500 Subject: [PATCH 1/5] fix multiple apps --- src/iohook.cc | 41 ++++++++++++++++++++--------------------- 1 file changed, 20 insertions(+), 21 deletions(-) diff --git a/src/iohook.cc b/src/iohook.cc index d518d3ef..300ee253 100644 --- a/src/iohook.cc +++ b/src/iohook.cc @@ -28,9 +28,9 @@ static std::queue zqueue; #ifdef _WIN32 static HANDLE hook_thread; -static HANDLE hook_running_mutex; -static HANDLE hook_control_mutex; -static HANDLE hook_control_cond; +static CRITICAL_SECTION hook_running_mutex; +static CRITICAL_SECTION hook_control_mutex; +static CONDITION_VARIABLE hook_control_cond; #else static pthread_t hook_thread; @@ -75,15 +75,15 @@ void dispatch_proc(uiohook_event * const event) { case EVENT_HOOK_ENABLED: // Lock the running mutex so we know if the hook is enabled. #ifdef _WIN32 - WaitForSingleObject(hook_running_mutex, INFINITE); + EnterCriticalSection(&hook_running_mutex); #else pthread_mutex_lock(&hook_running_mutex); #endif - + // Unlock the control mutex so hook_enable() can continue. #ifdef _WIN32 - // Signal the control event. - SetEvent(hook_control_cond); + WakeConditionVariable(&hook_control_cond); + LeaveCriticalSection(&hook_control_mutex); #else // Unlock the control mutex so hook_enable() can continue. pthread_cond_signal(&hook_control_cond); @@ -94,15 +94,14 @@ void dispatch_proc(uiohook_event * const event) { case EVENT_HOOK_DISABLED: // Lock the control mutex until we exit. #ifdef _WIN32 - WaitForSingleObject(hook_control_mutex, INFINITE); + EnterCriticalSection(&hook_control_mutex); #else pthread_mutex_lock(&hook_control_mutex); #endif // Unlock the running mutex so we know if the hook is disabled. #ifdef _WIN32 - ReleaseMutex(hook_running_mutex); - ResetEvent(hook_control_cond); + LeaveCriticalSection(&hook_running_mutex); #else #if defined(__APPLE__) && defined(__MACH__) // Stop the main runloop so that this program ends. @@ -148,7 +147,8 @@ void *hook_thread_proc(void *arg) { // Make sure we signal that we have passed any exception throwing code for // the waiting hook_enable(). #ifdef _WIN32 - SetEvent(hook_control_cond); + WakeConditionVariable(&hook_control_cond); + LeaveCriticalSection(&hook_control_mutex); return status; #else @@ -165,7 +165,7 @@ int hook_enable() { // Lock the thread control mutex. This will be unlocked when the // thread has finished starting, or when it has fully stopped. #ifdef _WIN32 - WaitForSingleObject(hook_control_mutex, INFINITE); + EnterCriticalSection(&hook_control_mutex); #else pthread_mutex_lock(&hook_control_mutex); #endif @@ -222,13 +222,13 @@ int hook_enable() { // event is received or the thread terminates. // NOTE This unlocks the hook_control_mutex while we wait. #ifdef _WIN32 - WaitForSingleObject(hook_control_cond, INFINITE); + SleepConditionVariableCS(&hook_control_cond, &hook_control_mutex, INFINITE); #else pthread_cond_wait(&hook_control_cond, &hook_control_mutex); #endif #ifdef _WIN32 - if (WaitForSingleObject(hook_running_mutex, 0) != WAIT_TIMEOUT) { + if (TryEnterCriticalSection(&hook_running_mutex) != FALSE) { #else if (pthread_mutex_trylock(&hook_running_mutex) == 0) { #endif @@ -262,7 +262,7 @@ int hook_enable() { // Make sure the control mutex is unlocked. #ifdef _WIN32 - ReleaseMutex(hook_control_mutex); + LeaveCriticalSection(&hook_control_mutex); #else pthread_mutex_unlock(&hook_control_mutex); #endif @@ -275,9 +275,9 @@ void run() { // thread has finished starting, or when it has fully stopped. #ifdef _WIN32 // Create event handles for the thread hook. - hook_running_mutex = CreateMutex(NULL, FALSE, TEXT("hook_running_mutex")); - hook_control_mutex = CreateMutex(NULL, FALSE, TEXT("hook_control_mutex")); - hook_control_cond = CreateEvent(NULL, TRUE, FALSE, TEXT("hook_control_cond")); + InitializeCriticalSection(&hook_running_mutex); + InitializeCriticalSection(&hook_control_mutex); + InitializeConditionVariable(&hook_control_cond); #else pthread_mutex_init(&hook_running_mutex, NULL); pthread_mutex_init(&hook_control_mutex, NULL); @@ -394,9 +394,8 @@ void stop() { #ifdef _WIN32 // Create event handles for the thread hook. CloseHandle(hook_thread); - CloseHandle(hook_running_mutex); - CloseHandle(hook_control_mutex); - CloseHandle(hook_control_cond); + DeleteCriticalSection(&hook_running_mutex); + DeleteCriticalSection(&hook_control_mutex); #else pthread_mutex_destroy(&hook_running_mutex); pthread_mutex_destroy(&hook_control_mutex); From d7e6dcc6622cc5e75aea2c8a946fbf9cefa958f4 Mon Sep 17 00:00:00 2001 From: chevon Date: Tue, 9 Feb 2021 11:49:53 -0500 Subject: [PATCH 2/5] drop old node version --- package.json | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/package.json b/package.json index ff00baa9..118807a2 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iohook", - "version": "0.7.2", + "version": "0.8.0", "description": "Node.js global keyboard and mouse hook", "main": "index.js", "types": "index.d.ts", @@ -93,11 +93,6 @@ "11.0.0", "85" ], - [ - "node", - "8.9.3", - "57" - ], [ "node", "9.2.0", From 16c19f748c5b08014dcf4aa1a9af0f1228ec3388 Mon Sep 17 00:00:00 2001 From: chevon Date: Tue, 9 Feb 2021 12:02:10 -0500 Subject: [PATCH 3/5] Remove node 9 as well --- package.json | 5 ----- 1 file changed, 5 deletions(-) diff --git a/package.json b/package.json index 118807a2..ba219c6f 100644 --- a/package.json +++ b/package.json @@ -93,11 +93,6 @@ "11.0.0", "85" ], - [ - "node", - "9.2.0", - "59" - ], [ "node", "10.0.0", From c288f9f99c5c28798def8992cdbdac7f8ceef232 Mon Sep 17 00:00:00 2001 From: chevon Date: Thu, 18 Mar 2021 12:58:36 -0400 Subject: [PATCH 4/5] bump major version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ba219c6f..6164dc98 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iohook", - "version": "0.8.0", + "version": "1.0.0", "description": "Node.js global keyboard and mouse hook", "main": "index.js", "types": "index.d.ts", From 98f258b932c92a568650f1a58f1a9e6981d301fb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mil=C3=A1n=20Nagy?= <123.wizek@gmail.com> Date: Mon, 5 Apr 2021 23:53:03 +0200 Subject: [PATCH 5/5] Change version to 0.9.0 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 6164dc98..cb154a46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "iohook", - "version": "1.0.0", + "version": "0.9.0", "description": "Node.js global keyboard and mouse hook", "main": "index.js", "types": "index.d.ts",