Agus_Darmawan

sendInput

Jul 3rd, 2019
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.14 KB | None | 0 0
  1. //
  2. // ctrlv.c - Simulates pressing Ctrl-V once a second
  3. //
  4. // Written by Ted Burke - last updated 18-10-2012
  5. //
  6. // To compile with MinGW:
  7. //
  8. //      gcc -o ctrlv.exe ctrlv.c
  9. //
  10. // To run the program:
  11. //
  12. //      ctrlv.exe
  13. //
  14.  
  15. // Because the SendInput function is only supported in
  16. // Windows 2000 and later, WINVER needs to be set as
  17. // follows so that SendInput gets defined when windows.h
  18. // is included below.
  19. #define WINVER 0x0500
  20. #include <windows.h>
  21.  
  22. int main()
  23. {
  24.     char kata[] = "Percobaan menekan tombol";
  25.     // Create a generic keyboard event structure
  26.     INPUT ip;
  27.     ip.type = INPUT_KEYBOARD;
  28.     ip.ki.wScan = 0;
  29.     ip.ki.time = 0;
  30.     ip.ki.dwExtraInfo = 0;
  31.    
  32.     sleep(2000);
  33.    
  34.     int i;
  35.     for(i=0; i<=strlen(kata); i++){
  36.       // tekan hurufnya
  37.       printf("%c ",kata[i]);
  38.       ip.ki.wVk = kata[i];
  39.       ip.ki.dwFlags = 0; // tekan tombol
  40.       SendInput(1, &ip, sizeof(INPUT));
  41.  
  42.       ip.ki.wVk = kata[i];
  43.       ip.ki.dwFlags = KEYEVENTF_KEYUP; // lepas tombol
  44.       SendInput(1, &ip, sizeof(INPUT));
  45.       sleep(1000);
  46.     }
  47.    
  48.     Sleep(1000);
  49.     getch();
  50.     return 0;
  51. }
Add Comment
Please, Sign In to add comment