#include #include #include static atomic_llong 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)); } 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) { if (hKeyboardHook) { 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); }