Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ mouse click on certain spot in window

Tags:

c++

c

winapi

I have my function here working, but I am certainly going about it the wrong way.

My program uses FindWindow to find the correct window. I need to double click on a specific location on this window.

I made it work by always putting the window in the same location on the screen, but if I moved the window the program would try click on the hard-coded location I have provided and it would not work.

Here is the function:

void lobbyWindow(HWND main_client)
{
  //RECT arect;

   // GetWindowRect(main_client, &arect); 

    SetCursorPos(748,294);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

}

As you can see I just move the mouse to 748,294 and double click. What I want to do is set the mouse to 100,100 in the main_client window, so if I move the main_client window the mouse still clicks on the correct spot.

like image 796
r-s Avatar asked Dec 16 '22 07:12

r-s


1 Answers

Use SendInput() instead, then you can use flags to move the cursor relative to the window -

Input.mi.dwFlags = MOUSEEVENTF_MOVE | MOUSEEVENTF_ABSOLUTE | MOUSEEVENTF_LEFTDOWN | MOUSEEVENTF_LEFTUP;

  1. How i can simulate a double mouse click on window ( i khow handle) on x, y coordinate, using SendInput?
  2. http://www.cplusplus.com/forum/windows/97017/
like image 59
Patt Mehta Avatar answered Jan 03 '23 22:01

Patt Mehta