473,246 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,246 software developers and data experts.

mouse_event help needed

I have an application for which I'd like to simulate mouse clicks.
What I want to do is simulate a click at a specific location in the
application. I've tried PostMessage to no avail. I had a bit more
success with mouse_event, however even this doesn't seem to actually
send a click in this application. The code is roughly as
follows (targetHwnd is the hWnd of the target window I'd like to click
in, and targetX/targetY are the x/y coordinates on the screen I want to
click at):

<code>
ForceForegroundWindow(targetHwnd);
int x = targetX * 65536 / Screen.PrimaryScreen.Bounds.Width;
int y = targetY* 65536 / Screen.PrimaryScreen.Bounds.Height;
mouse_event(MOUSEEVENTF_MOUSEMOVE | MOUSEEVENTF_ABSOLUTE, x, y, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0);
Sleep(10);
mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0);
</code>

This code works fine simulating a mouse click in every other
application I've tried. However, the one I'm interested in does not
respond - the window is brought to the foreground and gains input
focus, the mouse moves to the desire location at which point the
application changes the cursor's icon, and nothing happens. This code
works in creating a mouse click for any other application I've tried.

One thing to note about this application in which I'm trying to
simulate the click is that it does not have any child windows. There
are no buttons or forms whose hWnds I can grab. It appears to render
all buttons, scrollbars and such itself, without using Windows. I have
no clue why it doesn't seem to receive clicks - is there anything
anyone can think of that would explain this behavior? Hopefully I'm
just missing something about emulating mouse clicks in Windows.

Feb 5 '06 #1
4 7477
It sounds like you may have to do some system hook programming.
Curtis
http://www.ghostclip.com
The Premier Help System For Developers

Feb 6 '06 #2
"bowchow79" <bo*******@hotmail.com> wrote in message
news:11*********************@f14g2000cwb.googlegro ups.com...
This code works fine simulating a mouse click in every
other application I've tried. However, the one I'm
interested in does not respond - the window is brought
to the foreground and gains input focus, the mouse moves
to the desire location at which point the application changes
the cursor's icon, and nothing happens.
It may be hiding itself from this sort of stuff in all sorts of complicated
ways, or it may be doing something as simple as checking the time delay
between the "received focus" and the "click", or perhaps also between the
mousedown and the mouseup events in an attempt to discover whether the click
is likely to have been produced by a human operator. The delay between
mousedown and mouseup is typically in the region of 100 milliseconds or more
for a human operator, and perhaps a second or more between focus and
mousedown. Try introducing these delays in your code and see what happens.

Mike


This code works in creating a mouse click for any other application I've tried.

One thing to note about this application in which I'm trying to
simulate the click is that it does not have any child windows. There
are no buttons or forms whose hWnds I can grab. It appears to render
all buttons, scrollbars and such itself, without using Windows. I have
no clue why it doesn't seem to receive clicks - is there anything
anyone can think of that would explain this behavior? Hopefully I'm
just missing something about emulating mouse clicks in Windows.


Feb 6 '06 #3
"Mike Williams" <Mi**@WhiskyAndCoke.com> wrote in message
news:eJ**************@TK2MSFTNGP14.phx.gbl...

.. . . and you might also need to introduce a delay of a hundred milliseconds
or so between the mouse arriving at the desired position and the mousedown.

Mike


Feb 6 '06 #4
On 5 Feb 2006 14:43:59 -0800, "bowchow79" <bo*******@hotmail.com>
wrote:
I have an application for which I'd like to simulate mouse clicks.
What I want to do is simulate a click at a specific location in the
application. I've tried PostMessage to no avail. I had a bit more
success with mouse_event, however even this doesn't seem to actually
send a click in this application. The code is roughly as
follows (targetHwnd is the hWnd of the target window I'd like to click
in, and targetX/targetY are the x/y coordinates on the screen I want to
click at):


Are you absolutely sure that you have the right HWND ?

I would check that using WindowFromPoint

You could also try using Mouse_Event

SetCapture problems also spring to mind
Feb 6 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: System | last post by:
Hello All, Redhat 9.0 Mysql 3.23.56 ==> Running I want to upgarde to 4.0.13 but this is the error it says: # rpm -Uvh MySQL-server-4.0.13-0.i386.rpm warning: MySQL-server-4.0.13-0.i386.rpm: V3...
8
by: Stephen | last post by:
I am trying to add some code to below to include a datatable and fill the datatable. The reason for doing this is so as I can check to see whether there are any rows returned by the stored...
5
by: Steve | last post by:
Hi, I am sitting down to design our next set of internal apps. I would like to approach this in a way that would allow me to break logical parts of the application that handle specific tasks...
0
by: ultradiv | last post by:
I have a VB.NET application partly built that produces an xml output (just a file at present) I have a .NET webserver and SQLserver 2000 I need to be able to send the xml to the webserver/database...
13
by: Abhishek | last post by:
Hi, how do I pass the handle of a control to the win32 api mouse_event. so that it will create the click event on that application only even if there is any other window in front of it. I dont...
28
by: Ian Davies | last post by:
Hello I would appreciate some help from someone who has knowledge of working with css, php javascript and how they interact. Ive been working on a task for the last few days and have started to...
2
by: Atila Olah | last post by:
Hello everyone. I would like to be able to emit a mouse click on my xgl/compiz desktop, like I used to do in Windows: win32api.mouse_event(win32con.MOUSEEVENTF_LEFTDOWN, x, y, 0)...
1
by: dtzWill | last post by:
Hey all--I'm trying to implement the server-side code for some software I'm writing for the iPhone. Basically it's a wireless touchpad... so I have a client that sends events (runs on the phone)...
37
by: C_guy | last post by:
Does anyone know of a (hopefully free) tool that can traverse a project and determine which "#include"s are not needed or needed in every .C file? This would be helpful in removing header...
0
by: abbasky | last post by:
### Vandf component communication method one: data sharing ​ Vandf components can achieve data exchange through data sharing, state sharing, events, and other methods. Vandf's data exchange method...
0
by: stefan129 | last post by:
Hey forum members, I'm exploring options for SSL certificates for multiple domains. Has anyone had experience with multi-domain SSL certificates? Any recommendations on reliable providers or specific...
0
Git
by: egorbl4 | last post by:
Скачал я git, хотел начать настройку, а там вылезло вот это Что это? Что мне с этим делать? ...
0
by: MeoLessi9 | last post by:
I have VirtualBox installed on Windows 11 and now I would like to install Kali on a virtual machine. However, on the official website, I see two options: "Installer images" and "Virtual machines"....
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.