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..c926eef 100644 --- a/monitor.c +++ b/monitor.c @@ -1,31 +1,20 @@ -#include #include #include -static atomic_llong last_input_time = 0; +static long long last_input_time = 0; -HHOOK hKeyboardHook; -HHOOK hMouseHook; +HHOOK hKeyboardHook = NULL; 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 +22,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; }