Advertisement
CasualGamer

AutoClicker

May 10th, 2020 (edited)
6,548
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.33 KB | None | 0 0
  1. #include <iostream>
  2. #include <Windows.h>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8.     LPCWSTR window_title = L"Untitled - Paint";
  9.     HWND hWND = FindWindow(NULL, window_title);
  10.     while (hWND == NULL) {
  11.         hWND = FindWindow(NULL, window_title);
  12.         cout << "Start Paint!" << endl;
  13.         Sleep(100);
  14.     }
  15.     while (true) {
  16.         Sleep(50);
  17.         if (GetAsyncKeyState(VK_NUMPAD0)) { // Exit
  18.             return 0;
  19.         }
  20.         if (GetAsyncKeyState(VK_NUMPAD1)) {//Mouseposition
  21.             POINT p;
  22.             GetCursorPos(&p);
  23.             ScreenToClient(hWND, &p);
  24.             cout << "x-position: " << p.x << " | y-position: " << p.y << endl;
  25.             Sleep(1000);
  26.         }
  27.         if (GetAsyncKeyState(VK_NUMPAD2)) { // leftclick
  28.             INPUT iNPUT = { 0 };
  29.             iNPUT.type = INPUT_MOUSE;
  30.             iNPUT.mi.dwFlags = MOUSEEVENTF_LEFTDOWN;
  31.             SendInput(1, &iNPUT, sizeof(iNPUT));
  32.             ZeroMemory(&iNPUT, sizeof(iNPUT));
  33.             iNPUT.type = INPUT_MOUSE;
  34.             iNPUT.mi.dwFlags = MOUSEEVENTF_LEFTUP;
  35.             SendInput(1, &iNPUT, sizeof(iNPUT));
  36.         }
  37.         if (GetAsyncKeyState(VK_NUMPAD3)) { //write a
  38.             INPUT Input = { 0 };
  39.             Input.type = INPUT_KEYBOARD;
  40.             Input.ki.wVk = VkKeyScanA('a');
  41.             SendInput(1, &Input, sizeof(Input));
  42.             ZeroMemory(&Input, sizeof(Input));
  43.             Input.ki.dwFlags = KEYEVENTF_KEYUP;
  44.             SendInput(1, &Input, sizeof(Input));
  45.  
  46.         }
  47.         if (GetAsyncKeyState(VK_NUMPAD4)) { // Set mouse position using SendInput
  48.             int x = 100;
  49.             int y = 100;
  50.  
  51.             // Get total screen coordinates
  52.             int screen_x = GetSystemMetrics(SM_CXSCREEN);
  53.             int screen_y = GetSystemMetrics(SM_CYSCREEN);
  54.  
  55.             WINDOWPLACEMENT wp;
  56.             GetWindowPlacement(hWND, &wp);
  57.  
  58.             long xConverted = (65535 * (x + wp.rcNormalPosition.left)) / screen_x;
  59.             long yConverted = (65535 * (y + wp.rcNormalPosition.top)) / screen_y;
  60.  
  61.             INPUT iNPUT = { 0 };
  62.             iNPUT.type = INPUT_MOUSE;
  63.             iNPUT.mi.dwFlags = (MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_MOVE);
  64.             iNPUT.mi.dx = xConverted;
  65.             iNPUT.mi.dy = yConverted;
  66.             SendInput(1, &iNPUT, sizeof(iNPUT));
  67.  
  68.         }
  69.     }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement