Solved

Simulating the mouse

Posted on 1998-02-12
6
970 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
6 Comments
 

Author Comment

by:kwang080897
Comment Utility
Edited text of question
0
 
LVL 8

Expert Comment

by:ZifNab
Comment Utility
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
Comment Utility
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
Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 2

Expert Comment

by:mvz121697
Comment Utility
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
Comment Utility
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 400 total points
Comment Utility
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now