Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _WIN32_WINNT 0x0501
- #include <windows.h>
- int main(void) {
- const UINT fooKey = 65; // ascii value for 'a', ?case ignored?
- const UINT keySize = 2;
- INPUT keyIn[keySize];
- memset(keyIn, 0, sizeof(keyIn));
- keyIn[0].type = INPUT_KEYBOARD;
- // Key pressed down
- keyIn[0].ki.wScan = MapVirtualKey(fooKey, 0); //key we're going to "press"
- keyIn[0].ki.dwFlags = KEYEVENTF_SCANCODE; // wVk is ignored
- keyIn[0].ki.time = 0; // OS can provide timestamp, we don't care
- keyIn[0].ki.dwExtraInfo = 0;
- // Key released/up state
- keyIn[1].ki.wScan = MapVirtualKey(fooKey, 0);
- keyIn[1].ki.dwFlags = KEYEVENTF_SCANCODE | KEYEVENTF_KEYUP; // change state to up
- keyIn[1].ki.time = 0;
- keyIn[1].ki.dwExtraInfo = 0;
- while(1){ // ^C to escape
- // second arg should be array of INPUT objects, but bear with me...
- SendInput(1, keyIn[0], sizeof(INPUT) ); // send down only message
- Sleep(3000); // in ms
- SendInput(1, keyIn[1], sizeof(INPUT) ); // send up message, change state
- }
- return 0;
- } // Main
Advertisement
Add Comment
Please, Sign In to add comment