[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Simulate Mouse Click Within Your Program Area Form

Posted on 2005-04-13
4
Medium Priority
?
237 Views
Last Modified: 2010-04-05
hi, I need to simulate a mouse click at a certain point within the form area.

how do I do that?

with doing it from the desktop the code is
mouse_event(MOUSEEVENTF_LEFTDOWN, 100,100, 0, 0);
mouse_event(MOUSEEVENTF_LEFTUP, 100,100, 0, 0);

but the thing with that is you move the window, you got to change the x/y, if the x/y was within the program form area, then the program can be hidden or moved and it can still be clicked.

anyone know how I can do this?

Sal.
0
Comment
Question by:SaLz
4 Comments
 
LVL 17

Accepted Solution

by:
geobul earned 2000 total points
ID: 13774877
Hi,

The following works if you move the form (I don't think mouse clicks could be simulated if the form is hidden/minimized):

procedure TForm1.ClickAt(x,y: integer);
var
  p: TPoint;
begin
  // move the pointer
  p := Point(x,y);
  p := self.ClientToScreen(p);
  SetCursorPos(p.x, p.y);
  // click
  mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
  mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  ClickAt(10,10); // relative coordinates in Form1 client area
end;

Regards, Geo
0
 
LVL 11

Expert Comment

by:ZhaawZ
ID: 13777386
SendMessage(handle, wm_lbuttondown, 0, MakeLParam(40, 30));
SendMessage(handle, wm_lbuttonup  , 0, MakeLParam(40, 30));

40 is X coordinate, 30 - Y
0
 
LVL 1

Expert Comment

by:JustinWillis
ID: 13798539
I don't understand the question, if the above doesn't answer it then can you please try to explain more clearly what you are trying to do?
JustinWillis.
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Loops Section Overview
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question