Delphi32.com - Home!
| Home/News | Downloads | Forums | D32 Magazine | Resources | Info and Facts |  
 
 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

     



  << Previous Faq     Complete List     Next Faq >>  



 
 Hits/month  2,500,000+ 
 Downloads
 (Since May 2000)
 7,393,709 
 Total Files  6,023 
 Forum msgs  7,670 
 Articles/FAQs  70+/900+ 
Kylix
Tips n Tricks
FAQs
Knowledge Base
Bug Listings
Articles
Books
Newsgroups
Links
Submissions
Testimonials
Advertising
Contact Us
About Us
Search Amazon:
Top Selling Software at Amazon

| Home/News | Downloads | Forums | Resources | Info and Facts | Testimonials |
  Site Search:
 


Comments/Problems: Webmaster@delphi32.com
Copyright © 1998-2006, Delphi32.com. All rights reserved.
Terms of Use