Advertisement
LSJiqueue

SendInput working with games

Mar 26th, 2024
869
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.69 KB | None | 0 0
  1. #include <iostream>
  2. #include <windows.h>
  3. #include <stdlib.h>
  4. int main(){
  5.     while (true){
  6.         if (GetAsyncKeyState(0x51) & 0x8000){ //if pressed Q
  7.             SHORT key;
  8.             UINT mappedKey;
  9.             INPUT input { 0 };
  10.             key = VkKeyScan('e');
  11.             mappedKey = MapVirtualKey(LOBYTE(key), 0);
  12.             input.type = INPUT_KEYBOARD;
  13.             input.ki.dwFlags = KEYEVENTF_SCANCODE;
  14.             input.ki.wScan = mappedKey;
  15.             SendInput(1, &input, sizeof(input)); // key down
  16.             Sleep(500);
  17.             input.ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; //key up
  18.             SendInput(1, &input, sizeof(input));
  19.         };
  20.     }    
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement