Home > Software engineering >  Turn a postmessage magic
Turn a postmessage magic

Time:09-25

Recently boring postmessage was used to simulate the mouse button, achieve the goal of automatic chess operating process is a single board games crazystone
Use spy++ checked the game after the operation of the interface board is the HWND
Then write a demon
 the while (1) 
{
PostMessage (HWND, WM_MOUSEMOVE MK_LBUTTON, MAKELPARAM (x, y));
//Sleep (50);
PostMessage (HWND, WM_LBUTTONDOWN MK_LBUTTON, MAKELPARAM (x, y));
//Sleep (50);
PostMessage (HWND, WM_LBUTTONUP, 0, MAKELPARAM (x, y));
Sleep (200);
}
however, there is no use with spy++ to see the next message is received the x, y coordinates are right
Inadvertently run the circulation, use the mouse to move to the game interface
An amazing thing happened when I the mouse moves to a place I have began to automatic chess
Is very strange, I changed x y are so
For help once you requested

CodePudding user response:

Whether to set up the next focus first?
The BringWindowToTop (hGameWnd);
SetFocus (hGameWnd);

CodePudding user response:

reference 1st floor zgl7903 response:
to set up the first focus?
The BringWindowToTop (hGameWnd);
SetFocus (hGameWnd);

Still won't do what reason be

CodePudding user response:

Try to switch to mouse_event

CodePudding user response:

PostMessage (HWND WM_MOUSEMOVE, MK_LBUTTON , MAKELPARAM (x, y));
//Sleep (50);
PostMessage (HWND, WM_LBUTTONDOWN MK_LBUTTON, MAKELPARAM (x, y));

CodePudding user response:

SendInput

CodePudding user response:

A set of mouse messages to complete a mouse action, had better use mouse_event simulation

CodePudding user response:

The Post itself uncertain factors, does not guarantee success, change the Send

CodePudding user response:

Postmessage sends the message, this parameter will lose, suggest the address;
It should be so use sendmessage

CodePudding user response:

Simulation mouse operation mouse_event/SendInput ()

CodePudding user response:

1. The x, y is how to? Loop not to modify it, it is not only a PM?
2. To learn
  • Related