Re: simulating mouse clicks in Delphi


[ Delphi Forum ] [ Delphi Tutorials -- by DelphiLand ]

Posted by webmaster Guido on August 12, 2003 at 15:17:04:

In Reply to: simulating mouse clicks.. posted by Turek on August 11, 2003 at 12:45:23:

: SetCursorPos(x, y);
: mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
: mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

: this one will click on active window, but i need to do something like
: postmessage(wnd, WM_RBUTTONDOWN, 0, 0);
: but it clicks when i have cursor in that place where i want to click,
: postmessage(wnd, WM_RBUTTONDOWN, MK_RBUTTON,
MakeLong(x,y));
: does the same, and clicks in position where the mouse pointer is, i need it to click on inactive window... what i am makin wrong ??

-----------------

With the following sequence, you simulate a mouse click at the location 100 pixels from the left of the screen and 200 pixels from the top of the screen:

SetCursorPos(100, 200);
Mouse_Event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Mouse_Event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);

Contrary to what you wrote, this is not limited to the "active" window, but you can simulate a mouse click on any position of the screen, be it a button, menu, shortcut, or whatever in any *visible* window of any application or even on the desktop. In short, if you simulate a mouseclick in this way, it is exactly the same as if you would move and click the mouse manually.

Note: in SetCursorPos(X, Y) the coordinates are relative to the screen, not relative to the client area of your Delphi-form.


Related Articles and Replies:

 


[ Delphi Forum ]
[ DelphiLand: free Delphi source code, tips, tutorials ]