C ++ simulates a left click on a minimized program

I was looking a little about this particular problem that I have, I want to be able to simulate left-clicking on the program to which I am attached.

At the moment I am creating a thread that checks the database for specific values, and when these values ​​are returned (the ones I am looking for), I want to be able to then send a left click in any x, y coordination of the program (while minimizing).

How to do it for Windows 7? Thanks!

EDIT: That's what I call a thread ...

HWND child = GetActiveWindow(); if ( child == NULL ) MessageBox(0,"Couldn't get the child hwnd!","",0); DWORD ID; HANDLE thread_check_game = CreateThread ( NULL , 0 , (LPTHREAD_START_ROUTINE) game_check_thread , (LPVOID)child, 0 , &ID ); CloseHandle ( game_check_thread ); 

and then...

 DWORD WINAPI game_check_thread(LPVOID lpParam) { HWND Window; Window = (HWND)lpParam; // ... some other code ... // ... WORD mouseX = 398; WORD mouseY = 398; SendMessage(Window,WM_LBUTTONDOWN,MK_LBUTTON,MAKELPARAM(mouseX,mouseY)); SendMessage(Window, WM_LBUTTONUP, MK_LBUTTON, MAKELPARAM(mouseX, mouseY)); Write("Sent Left Click\n"); ExitThread(0); return 0; } 
+4
source share
1 answer

If you want to trigger a mouse event in your application, use the SendMessage function, and your message will appear in a window with a manual message of hWnd messages.

 SendMessage(hWnd, WM_LBUTTONDOWN, MK_LBUTTON, MAKELPARAM(mousePosX, mousePosY)); 

You may need to notify WM_LBUTTONUP , depending on how the application handles mouse events.

+4
source

All Articles