2024-10-07 21:53:11 +02:00
|
|
|
#include <stdatomic.h>
|
2024-10-07 20:23:21 +02:00
|
|
|
#include <time.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
2024-10-07 21:53:11 +02:00
|
|
|
static atomic_llong last_input_time = 0;
|
2024-10-07 20:23:21 +02:00
|
|
|
|
|
|
|
HHOOK hKeyboardHook;
|
2024-10-07 21:53:11 +02:00
|
|
|
HHOOK hMouseHook;
|
2024-10-07 20:23:21 +02:00
|
|
|
|
|
|
|
LRESULT CALLBACK KeyboardHookProc(int nCode, WPARAM wParam, LPARAM lParam) {
|
|
|
|
if (nCode == HC_ACTION) {
|
2024-10-07 21:53:11 +02:00
|
|
|
atomic_store(&last_input_time, time(NULL));
|
2024-10-07 20:23:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return CallNextHookEx(hKeyboardHook, nCode, wParam, lParam);
|
|
|
|
}
|
|
|
|
|
2024-10-07 21:53:11 +02:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-10-07 20:23:21 +02:00
|
|
|
__declspec(dllexport) void start_hook(void) {
|
|
|
|
hKeyboardHook = SetWindowsHookEx(WH_KEYBOARD_LL, KeyboardHookProc, NULL, 0);
|
2024-10-07 21:53:11 +02:00
|
|
|
hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, MouseHookProc, NULL, 0);
|
2024-10-07 20:23:21 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
__declspec(dllexport) void stop_hook(void) {
|
2024-10-07 21:53:11 +02:00
|
|
|
if (hKeyboardHook) {
|
|
|
|
UnhookWindowsHookEx(hKeyboardHook);
|
|
|
|
hKeyboardHook = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (hMouseHook) {
|
|
|
|
UnhookWindowsHookEx(hMouseHook);
|
|
|
|
hMouseHook = NULL;
|
|
|
|
}
|
2024-10-07 20:23:21 +02:00
|
|
|
}
|
|
|
|
|
2024-10-07 21:53:11 +02:00
|
|
|
__declspec(dllexport) time_t last_time_input_received(void) {
|
|
|
|
return atomic_load(&last_input_time);
|
2024-10-07 20:23:21 +02:00
|
|
|
}
|