Solved

Simulating the mouse

Posted on 1998-02-12
6
986 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering 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

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…
Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses
Course of the Month9 days, left to enroll

615 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