Death420

sendKey.cpp

Mar 8th, 2020
305
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.70 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #pragma comment (lib, "user32")
  4. bool keyPressed(char key)
  5. {
  6.     return GetAsyncKeyState(key) == -32767;
  7. }
  8. void sendKey(char key)
  9. {
  10.     INPUT ip;  
  11.     ip.type = INPUT_KEYBOARD;
  12.     ip.ki.wScan =  0;
  13.     ip.ki.time = 0;
  14.     ip.ki.dwExtraInfo = 0;         
  15.    
  16.     ip.ki.dwFlags = 0;
  17.     ip.ki.wVk = key;   
  18.     SendInput(1, &ip, sizeof(INPUT));  
  19.     ip.ki.dwFlags = KEYEVENTF_KEYUP;
  20.     SendInput(1, &ip, sizeof(INPUT));
  21. }
  22. int main()
  23. {      
  24.     std::cout << "Running...\n";   
  25.     int delay = 16;
  26.     char originalKey = VK_SPACE;
  27.     char keyToSend = VK_LWIN;
  28.     while(true)
  29.     {
  30.         if(keyPressed(originalKey))
  31.         {
  32.             sendKey(keyToSend);
  33.             std::cout << "PRESSED\n";      
  34.         }
  35.         Sleep(delay);
  36.     }    
  37. }
Advertisement
Add Comment
Please, Sign In to add comment