Thread View: microsoft.public.vb.winapi
5 messages
5 total messages
Started by bowchow79
Sun, 05 Feb 2006 22:43
mouse_event help needed
Author: bowchow79
Date: Sun, 05 Feb 2006 22:43
Date: Sun, 05 Feb 2006 22:43
34 lines
3216 bytes
3216 bytes
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.
Re: mouse_event help needed
Author: Light
Date: Mon, 06 Feb 2006 03:43
Date: Mon, 06 Feb 2006 03:43
4 lines
1706 bytes
1706 bytes
It sounds like you may have to do some system hook programming. Curtis http://www.ghostclip.com The Premier Help System For Developers
Re: mouse_event help needed
Author: Mike Williams
Date: Mon, 06 Feb 2006 08:37
Date: Mon, 06 Feb 2006 08:37
35 lines
2935 bytes
2935 bytes
"bowchow79" <bowchow79@hotmail.com> wrote in message news:1139179439.013311.39470@f14g2000cwb.googlegroups.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. >
Re: mouse_event help needed
Author: Mike Williams
Date: Mon, 06 Feb 2006 08:41
Date: Mon, 06 Feb 2006 08:41
7 lines
1592 bytes
1592 bytes
"Mike Williams" <Mike@WhiskyAndCoke.com> wrote in message news:eJwRFivKGHA.2012@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
Re: mouse_event help needed
Author: J French
Date: Mon, 06 Feb 2006 10:40
Date: Mon, 06 Feb 2006 10:40
19 lines
2156 bytes
2156 bytes
On 5 Feb 2006 14:43:59 -0800, "bowchow79" <bowchow79@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
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads