From 02ee2d14573dc18883e81643a873047da3003b49 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Mon, 7 Oct 2024 22:12:02 +0200 Subject: [PATCH] remove mouse support --- AutoOBSRBRestart.lua | 5 +++-- monitor.c | 23 ++++------------------- 2 files changed, 7 insertions(+), 21 deletions(-) diff --git a/AutoOBSRBRestart.lua b/AutoOBSRBRestart.lua index 0744990..1d93e07 100644 --- a/AutoOBSRBRestart.lua +++ b/AutoOBSRBRestart.lua @@ -15,7 +15,7 @@ function script_load() ffi.cdef[[ void start_hook(void); void stop_hook(void); - time_t last_time_input_received(void); + long long last_input_received(void); ]] monitor = ffi.load(script_path() .. "monitor.dll") @@ -25,6 +25,7 @@ end function script_unload() obs.timer_remove(check_restart) obs.timer_remove(check_idle) + monitor.stop_hook() end function check_restart() @@ -34,7 +35,7 @@ end function check_idle() local current_time = os.time() - local last_input_time = monitor.last_time_input_received() + local last_input_time = monitor.last_input_received() if current_time - last_input_time >= idle_time then monitor.stop_hook() diff --git a/monitor.c b/monitor.c index 9ff555b..babbc5d 100644 --- a/monitor.c +++ b/monitor.c @@ -2,30 +2,20 @@ #include #include -static atomic_llong last_input_time = 0; +static long long last_input_time = 0; HHOOK hKeyboardHook; -HHOOK hMouseHook; LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) { if (nCode == HC_ACTION) { - atomic_store(&last_input_time, time(NULL)); + last_input_time = time(NULL); } return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam); } -LRESULT CALLBACK MouseHookProc(int nCode, WPARAM wParam, LPARAM lParam) { - if (nCode == HC_ACTION) { - atomic_store(&last_input_time, time(NULL)); - } - - return CallNextHookEx(hMouseHook, nCode, wParam, lParam); -} - __declspec(dllexport) void start_hook(void) { hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0); - hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0); } __declspec(dllexport) void stop_hook(void) { @@ -33,13 +23,8 @@ __declspec(dllexport) void stop_hook(void) { UnhookWindowsHookEx(hKeyboardHook); hKeyboardHook = NULL; } - - if (hMouseHook) { - UnhookWindowsHookEx(hMouseHook); - hMouseHook = NULL; - } } -__declspec(dllexport) time_t last_time_input_received(void) { - return atomic_load(&last_input_time); +__declspec(dllexport) long long last_input_received(void) { + return last_input_time; }