Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <windows.h>
- #pragma comment (lib, "user32")
- bool keyPressed(char key)
- {
- return GetAsyncKeyState(key) == -32767;
- }
- void sendKey(char key)
- {
- INPUT ip;
- ip.type = INPUT_KEYBOARD;
- ip.ki.wScan = 0;
- ip.ki.time = 0;
- ip.ki.dwExtraInfo = 0;
- ip.ki.dwFlags = 0;
- ip.ki.wVk = key;
- SendInput(1, &ip, sizeof(INPUT));
- ip.ki.dwFlags = KEYEVENTF_KEYUP;
- SendInput(1, &ip, sizeof(INPUT));
- }
- int main()
- {
- std::cout << "Running...\n";
- int delay = 16;
- char originalKey = VK_SPACE;
- char keyToSend = VK_LWIN;
- while(true)
- {
- if(keyPressed(originalKey))
- {
- sendKey(keyToSend);
- std::cout << "PRESSED\n";
- }
- Sleep(delay);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment