Advertisement
vlatkovski

Clipboard Typer

Oct 2nd, 2018
385
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.62 KB | None | 0 0
  1. #include <iostream>
  2. #include <sstream>
  3. #define WINVER 0x0601
  4. #include <windows.h>
  5. using namespace std;
  6.  
  7. /*
  8. 1. copy some text
  9. 2. enter any character and press enter
  10. 3. after 1.5 seconds it will type it
  11. */
  12.  
  13.  
  14. INPUT ip;
  15. HKL kbl;
  16.  
  17. inline short getVKCode(char ch) {
  18.     return VkKeyScanExA(ch, kbl);
  19. }
  20.  
  21. string getClipboard() {
  22.     HANDLE h;
  23.     if (!OpenClipboard(NULL)) return "";
  24.     h = GetClipboardData(CF_TEXT);
  25.     return string((char *)h);
  26. }
  27.  
  28. void keyDown(short c) {
  29.     ip.ki.wVk = c;
  30.     ip.ki.dwFlags = 0; //keydown
  31.     SendInput(1, &ip, sizeof(INPUT));
  32. }
  33.  
  34. void keyUp(short c) {
  35.     ip.ki.wVk = c;
  36.     ip.ki.dwFlags = KEYEVENTF_KEYUP;
  37.     SendInput(1, &ip, sizeof(INPUT));
  38. }
  39.  
  40. int main() {
  41.  
  42.     bool useshift[200] = {};
  43.     {
  44.         string s = "ABCDEFGHIJKLMNOPQRSTUVWXYZ<>:\"{}()!@#$%^&*_+~";
  45.         for (char ch : s) {
  46.             useshift[(int)ch] = 1;
  47.         }
  48.     }
  49.  
  50.     kbl = GetKeyboardLayout(0);
  51.     ip.type = INPUT_KEYBOARD;
  52.     ip.ki.wScan = 0;
  53.     ip.ki.time = 0;
  54.     ip.ki.dwExtraInfo = 0;
  55.  
  56.     while (1) {
  57.         string waitstr;
  58.         getline(cin, waitstr);
  59.         string towrite = getClipboard();
  60.         Sleep(1500);
  61.         for (int i = 0; i < (int)towrite.length(); ++i) {
  62.             char ch = towrite[i];
  63.             if (useshift[(int)ch]) {
  64.                 keyDown(0x10);
  65.                 Sleep(1);
  66.             }
  67.             keyDown(getVKCode(ch));
  68.             Sleep(5);
  69.             keyUp(getVKCode(ch));
  70.             Sleep(5);
  71.             if (useshift[(int)ch]) {
  72.                 keyUp(0x10);
  73.                 Sleep(1);
  74.             }
  75.         }
  76.     }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement