STANAANDREY

mouse

Mar 30th, 2020 (edited)
324
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.23 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. #define WINVER 0x0500
  4. #include <windows.h>
  5. using namespace std;
  6. // Forward declaration of the LeftClick function
  7. void LeftClick ( );
  8. // Forward declaration of the MouseMove function
  9. void MouseMove ( int x, int y );
  10. int main()
  11. {
  12.  
  13.     Sleep(5000);
  14.     MouseMove(300, 300);
  15.     LeftClick();
  16.     return 0;
  17. }
  18. // LeftClick function
  19. void LeftClick ()
  20. {
  21.     INPUT Input = {};
  22.     // left down
  23.     Input.type      = INPUT_MOUSE;
  24.     Input.mi.dwFlags  = MOUSEEVENTF_LEFTDOWN;
  25.     ::SendInput(1,&Input,sizeof(INPUT));
  26.     // left up
  27.     ::ZeroMemory(&Input,sizeof(INPUT));/*
  28.     Input.type      = INPUT_MOUSE;
  29.     Input.mi.dwFlags  = MOUSEEVENTF_LEFTUP;
  30.     ::SendInput(1,&Input,sizeof(INPUT));//*/
  31. }
  32. // MouseMove function
  33. void MouseMove (int x, int y )
  34. {
  35.     double fScreenWidth    = ::GetSystemMetrics( SM_CXSCREEN )-1;
  36.     double fScreenHeight  = ::GetSystemMetrics( SM_CYSCREEN )-1;
  37.     double fx = x*(65535.0f/fScreenWidth);
  38.     double fy = y*(65535.0f/fScreenHeight);
  39.     INPUT  Input= {0};
  40.     Input.type      = INPUT_MOUSE;
  41.     Input.mi.dwFlags  = MOUSEEVENTF_MOVE|MOUSEEVENTF_ABSOLUTE;
  42.     Input.mi.dx = fx;
  43.     Input.mi.dy = fy;
  44.     ::SendInput(1,&Input,sizeof(INPUT));
  45. }
Add Comment
Please, Sign In to add comment