Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How can I simulate mouse clicks in my application written in Delphi? Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
Simulate Mouse Clicks and Moves 04-Oct-03
Category
Win API
Language
Delphi 3.x
Views
158
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Sebastian Volland

How can I simulate mouse clicks in my application written in Delphi?

Answer:

You can easily simulate mouse clicks or moves with the mouse_event-function. You 
can find more information about the parameters and flags for this function in the 
Delphi-helpfile. 

This function can be useful when you can not control other applications by OLE or 
something like that. 

Example: 

You want to start an application, and doubleclick on an item which is at 
x,y-position 300,400 in this application. Put a TTimer on your form, set it to 
Disabled and try this example code: 

1   procedure TForm1.FormCreateOrWhatever;
2   begin
3     winexec('myexternalapplication.exe', sw_shownormal); // start app
4     timer1.interval := 2000; // give the app 2 secs to start up
5     timer1.enabled := true; // start the timer
6   end;
7   
8   procedure TForm1.Timer1Timer(Sender: TObject);
9   var
10    point: TPoint; // point-structure needed by getcursorpos()
11  begin
12    getcursorpos(point); // get current mouse position
13    setcursorpos(300, 400); // set mouse cursor to menu item or whatever
14    mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0); // click down
15    mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0); // +click up = double click
16    setcursorpos(point.x, point.y); // set cursor pos to origin pos
17    timer1.enabled := false; // stop
18  end;


The timer is needed to give the application time to start up. Be sure you don't move the mouse while mouse_event is executed. That's it! 

			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC