Repository navigation
Expand file tree
/
Copy pathcheck_key.cpp
More file actions
88 lines (69 loc) · 2.26 KB
/
Copy pathcheck_key.cpp
File metadata and controls
88 lines (69 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#include <windows.h>
#include "hook.h"
// Global state
static bool g_logging_active = FALSE;
static HANDLE g_hotkey_thread = NULL;
static bool g_hotkey_thread_running = FALSE;
// Callback function pointer - you implement this
static void (*g_on_logging_toggle)(bool new_state) = NULL;
// Hotkey monitoring thread
DWORD WINAPI HotkeyThread(LPVOID param) {
LogMessage("F9 hotkey monitoring started");
while (g_hotkey_thread_running) {
// Check for F9 key press
if (GetAsyncKeyState(VK_F9) & 0x8000) {
// Wait for key release to avoid multiple triggers
while (GetAsyncKeyState(VK_F9) & 0x8000) {
Sleep(50);
}
// Toggle logging state
g_logging_active = !g_logging_active;
LogMessage("F9 pressed - Logging %s", g_logging_active ? "ENABLED" : "DISABLED");
// Call your callback function if set
if (g_on_logging_toggle) {
g_on_logging_toggle(g_logging_active);
}
}
Sleep(100); // Check every 100ms
}
return 0;
}
// Initialize F9 hotkey detection
bool InitializeF9Hotkey(void (*callback)(bool)) {
if (g_hotkey_thread_running) return TRUE;
g_on_logging_toggle = callback;
g_hotkey_thread_running = TRUE;
g_hotkey_thread = CreateThread(NULL, 0, HotkeyThread, NULL, 0, NULL);
if (g_hotkey_thread) {
LogMessage("F9 hotkey system initialized - Press F9 to toggle logging");
return TRUE;
} else {
LogMessage("Failed to create F9 hotkey thread");
g_hotkey_thread_running = FALSE;
return FALSE;
}
}
// Get current logging state
BOOL IsLoggingActive() {
return g_logging_active;
}
// Manually set logging state (if needed)
void SetLoggingActive(BOOL active) {
if (g_logging_active != active) {
g_logging_active = active;
if (g_on_logging_toggle) {
g_on_logging_toggle(g_logging_active);
}
}
}
// Cleanup
void CleanupF9Hotkey() {
if (!g_hotkey_thread_running) return;
g_hotkey_thread_running = FALSE;
if (g_hotkey_thread) {
WaitForSingleObject(g_hotkey_thread, 1000);
CloseHandle(g_hotkey_thread);
g_hotkey_thread = NULL;
}
LogMessage("F9 hotkey system cleaned up");
}