Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Simulating the mouse

Posted on 1998-02-12
6
Medium Priority
?
993 Views
Last Modified: 2011-10-03
Im Using Delphi 3 in a Windows95 Enviroment:

Is it posible to activate other applications and do mouse events in those application(Press buttons, Menus and other).

I want things to happen like if i was manually moving the mouse around my screen, but i want to do it from my application.

I dont know the handle of the window i want to activate, it depends on the position af the mouse.

I have tried sending a WM_LBUTTONDOWN message to another application by pressing a button(Not mouse button), but the message seem to be send to my application and not to the other application (When using Winsight). Winsight returns something like this:
0000:00000528 (other application name) WM_LBUTTONDOWN (position) Dispatched
but only when i mark the process of my application, not (other application)

I hope someone understand this question !

PS. I'm not very good at API Calls, so i would like some sample code


0
Comment
Question by:kwang080897
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Author Comment

by:kwang080897
ID: 1359069
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359070
You always need to know the handle of that window, eg. example minimizing another application from delphi.

First you need to get the HWND (Window Handle see the WinAPI help) of the
window you want to close (The subject of another thread here.) Then try
this Windows API routine. SendMessage( hWnd, WM_SIZE, SIZE_MINIMIZED, 0);
This sends the message to the window in hWnd, that the user pressed
the minmize box or selected it from the system menu.
0
 
LVL 8

Expert Comment

by:ZifNab
ID: 1359071
If you don't know the handle, but the caption, you can use did :

You can send the application a WM_QUIT message;

Example:
PostMessage(FindWindow(Nil, 'window caption'), WM_SIZE, SIZE_MINIMIZED, 0);

So what you need to do is :
 
PostMessage(FindWindow(Nil, 'window caption'), WM_LBUTTONDOWN, wParam, lParam)

But I think that you need the handle of a button, when you use WM_LBUTTONDOWN. Like :

PostMessage(BitBtn1.Handle, WM_LBUTTONDOWN, Word(0), LongInt(0)) ;

Try to send a mouse click message.

Where "window caption" is the caption of the window that you
are sending the message to.

Regards, Zif.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 2

Expert Comment

by:mvz121697
ID: 1359072
Here's some code i used to automate PC-Anywhere.
I searched for a button-window in a dialog.
I did a lot of testing with the GetWindow calls,
to try to find the right window-handle.
The name CONNSTAT is the classname of the PCA- main window. I looked it up with a spy-utility like winsight.
(BTW: You can not hard-code the window-handle-numbers.
Windows assigns them, and they can be different every time
the p[rogram run's)

procedure TForm1.Button1Click(Sender: TObject);
var
  n,w1:integer;
  SI: TStartupInfo;
  PI: TProcessInformation;
  Proc,WinHandle: THandle;
  c:string;
begin
  WinHandle := FindWIndow( 'CONNSTAT', nil );
  if(0 <> WinHandle )then
  begin
       W1:=GetWindow(WinHandle,GW_CHILD);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       W1:=GetWindow(W1,GW_HWNDNEXT);
       SendMessage(W1,WM_KEYDOWN,32,0);
       SendMessage(W1,WM_KEYUP,32,0);
   end;

0
 

Author Comment

by:kwang080897
ID: 1359073
My problem is:

I have to application running:
First application creates a file on a Network server, that tells the other application what to do

The other is picking up the file and doing the things  commanded in the file,  so i can control that maschine remote. Therefore i dont know the windows captions, and the button names, I want to be able to move the mouse around and click like if i was sitting infront of that machine.(I dont need to see the screen input, i'll solve that problem later) .

I dont think I can use the answer i got, if i can please explain

Thank you for trying - hope you can help me futher
PS. I will not be able to respont to comments and answer before Monday

0
 
LVL 8

Accepted Solution

by:
MikeP090797 earned 1600 total points
ID: 1359074
You can use WindowFromPoint to get a location of a window at a specific point. After that, you can get the child window of that point using ChildWindowFromPoint or ChildWindowFromPointEx. Then you can use SendMessage to send comamnds to the parent or child windows
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

670 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