Solved

Simulating the mouse

Posted on 1998-02-12
6
982 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
Industry Leaders: 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 400 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

Industry Leaders: 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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Print Graphic and Text to Epson TM-T88v 12 544
Convert a string into a TDateTime 5 79
CheckListBox usage 3 96
TAction.OnAfterExecute? 2 31
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…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

737 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