B
bowchow79
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.
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.