Solved

Simulate a mouse click on a window without focus or minimised to a specific x/y into this window

Posted on 2007-11-27
13
2,204 Views
Last Modified: 2013-11-23
Hi!
Just wonder how to simulate a mouse click into a specific posistion of a hidden/inactive/minimise window.

For exemple, I know the handle of a process.exe
I know that this handle window size is 480x320 and would like to simulate a click inside it at 355x155

Any idea?
0
Comment
Question by:Cédric MARCOUX
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20356941
Here is my currunt code that not works
procedure TFRM_Main.Button3Click(Sender: TObject);
var AppzHandle : THandle; 
classname: array[0..255] of char; //
var hwndWinamp : THandle; 
begin
AppzHandle := FindWindow(nil,'My application');
GetClassName(AppzHandle,ClassName,SizeOf(ClassName));
hwndWinamp := FindWindow(classname,nil);
PostMessage(hwndWinamp, WM_RBUTTONDOWN, MK_RBUTTON,MakeLong(48,55));
sleep(1000);
PostMessage(hwndWinamp, WM_RBUTTONUP, MK_RBUTTON,MakeLong(48,55));
end;

Open in new window

0
 
LVL 28

Expert Comment

by:2266180
ID: 20357335
I tried the following and it workd (using total commander:

what you need to do is:
- find the window that uniquely identifies your target application
- work your way down until you find the child window you are interested in

one good tool to help you with this is http://www.greatis.com/delphicb/windowse/
var AppzHandle : THandle;
    hwndWinamp : THandle;
begin
  AppzHandle := FindWindow('TTOTAL_CMD', nil);
  assert(AppzHandle<>0);
  hwndWinamp := FindWindowEx(appzhandle, 0, 'TMyListBox',nil);
  assert(hwndWinamp<>0);
  PostMessage(hwndWinamp, WM_LBUTTONDOWN, MK_LBUTTON,MakeLong(500,500));
  sleep(1000);
  PostMessage(hwndWinamp, WM_LBUTTONUP, 0,MakeLong(500,500));
end

Open in new window

0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20357385
my appz has no child cause this is a direct3d apllication...
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

 
LVL 28

Expert Comment

by:2266180
ID: 20357705
I thought you ere trying something on winamp because of the variable name.

why didn't you specify that? it's a pretty important detail as a driectx application is not similar to win32 application and it doesn't behave like on either.

I'm not even sure if you can do that since as I remember, directx appications use some directx drivers for mouse/keyboard/etc. you coul try sending directly to the directx window if you are not in fullscreen, and that might work.
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 20357723
0
 
LVL 21

Expert Comment

by:developmentguru
ID: 20357738
The only possible problem I see is that your window is minimized.  Since SendInput simulates the input at the lowest possible level, the recipient window would need to have focus.
0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20358274
I don't try to to that on winamp, it's just a piece of code from another appz, but the target appz is a game...
And to be exact, the application is hidden using SW_HIDE not minimised
0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20364528
Any idea?
I know that other program can do it...
Increased to 500
0
 
LVL 28

Expert Comment

by:2266180
ID: 20365284
not in my area of expertiese (directx). sorry.
0
 
LVL 21

Accepted Solution

by:
developmentguru earned 500 total points
ID: 20365313
 Did you try the PAQ?  From what I can see SendInput is your only option due to the DriectX.  If the game is using DriectInput then sending windows messages will not work.

  If you are the one hiding the application then, instead of hiding it you could move it off screen.  this would allow it to retain focus and be used with the SendInput, while not being visible.  For testing purposes I would first determine if it will give it the commands while you can see it anyway.  This way you know the SendInput works for the DirectX.  With that out of the way, try hiding it.  If that breaks the code that worked, then try a different way of making it disappear.
0
 
LVL 1

Author Comment

by:Cédric MARCOUX
ID: 20367068
will try, thanks for trick
0
 
LVL 1

Expert Comment

by:Computer101
ID: 20632777
Forced accept.

Computer101
EE Admin
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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

Suggested Solutions

In our object-oriented world the class is a minimal unit, a brick for constructing our applications. It is an abstraction and we know well how to use it. In well-designed software we are not usually interested in knowing how objects look in memory. …
Here is a helpful source code for C++ Builder programmers that allows you to manage and manipulate HTML content from C++ code, while also handling HTML events like onclick, onmouseover, ... Some objects defined and used in this source include: …
THe viewer will learn how to use NetBeans IDE 8.0 for Windows to perform CRUD operations on a MySql database.
The viewer will learn how to use and create keystrokes in Netbeans IDE 8.0 for Windows.

828 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