| |
| Using mouse_event() to similate mouse events |
 |
How do I use the mouse_event() procedure to simulate a mouse
event?
The following example demonstrates using the Windows API
function mouse_event() to simulate a mouse event. When Button2
is clicked, the example code places the mouse over Button and
clicks it. Mouse Coordinates given are in "Mickeys", where
their are 65535 "Mickeys" to a screen's width. procedure TForm .Button Click(Sender: TObject);
begin
ShowMessage('Button clicked');
end; procedure TForm .Button2Click(Sender: TObject);
var
Pt : TPoint;
begin
{Allow Button2 to repaint it's self}
Application.ProcessMessages;
{Get the point in the center of button }
Pt.x := Button .Left + (Button .Width div 2);
Pt.y := Button .Top + (Button .Height div 2);
{Convert Pt to screen coordinates}
Pt := ClientToScreen(Pt);
{Convert Pt to mickeys}
Pt.x := Round(Pt.x * (65535 / Screen.Width));
Pt.y := Round(Pt.y * (65535 / Screen.Height));
{Move the mouse}
Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_MOVE,
Pt.x,
Pt.y,
0,
0);
{Simulate the left mouse button down}
Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_LEFTDOWN,
Pt.x,
Pt.y,
0,
0);;
{Simulate the left mouse button up}
Mouse_Event(MOUSEEVENTF_ABSOLUTE or
MOUSEEVENTF_LEFTUP,
Pt.x,
Pt.y,
0,
0);;
end; 7/ 6/98 4:3 :28 PM
|
|
| Hits/month |
2,500,000+ |
Downloads (Since May 2000) |
7,393,709 |
| Total Files |
6,023 |
| Forum msgs |
7,670 |
| Articles/FAQs |
70+/900+ |
Top Selling Software at Amazon
|