Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

mosue_event/SendInput (from C#.NET)?

218 views
Skip to first unread message

Chris

unread,
May 14, 2002, 2:51:02 PM5/14/02
to
I seem unable to acheive what should be a simple event, a
click on the menu item of another application.

My application needs to send a message to another window
emulating a mouse click on (for example) the File menu
Item - resulting in the display of that item's sub-menu.

To add to my frustration, I have been able to emulate
clicks in the client area of other applications (using the
Windows SendMessage(..., WM_LBUTTONDOWN,...) function. I
have also been able to acheive the end result of menu
selection (i.e. I can get the SaveAs Command to work, as
if I select File->SaveAs with the mouse, but I then miss
the needed parts inbetween, the displaying of the sub-
menus), using SendMessage(..., WM_COMMAND,...).

I have attempted the following to emulate a mouse click in
the Non-Client Area of another applications window:

SendInput(...) (I am using Windows 2000);
- I get a return value equaling the number of messages
sent, in this case 1, but using s++ I can see that the
window is not getting the mouse event.

mouse_event(...) (for good measure);
- As expected no message is sent to the window, but
neither is and error code given when using GetLastError().

SendMessage(..., WM_LBUTTONDOWN,...),
SendMessage(.,WM_LBUTTONUP);
- I can see that the window is getting the message, but
the expected action (sub-menu dropping down) does not
occur;

SendMessage(..., WM_NCLBUTTONDOWN,...);
- The window gets the message, it begins the menu loop
and exits it immediately, and the sub-menu is never
displayed. The cursor despite using SetCursorPos() is not
right over the menu item.

I have tried all of the above while using SetCapture(...)
(and ReleaseCapture()) and the application's thread is
attached to thread of the Window it is attempting to send
a mouse message to (using AttachThreadInput(...). I have
also made sure the window has the focus (SetFocus(...)),
and is brought to the forefront(SetForegroundWindow(...));

Additional Information: I am using .NET (EA 7.0). My
application is written in C#, and imports the Windows
Functions from User32.dll and Kernel32.dll. The
applications that I am attempting to emulate mouse clicks
on are Windows applications (written in C++);

Does anyone have a suggestion on what I should try?

Gagandeep Singh

unread,
May 15, 2002, 3:11:36 PM5/15/02
to
Hi Chris,
As per Platform SDK documentation WM_LBUTTONDOWN is a posted
message. So you need to call PostMessage(hWnd, WM_LBUTTONDOWN,....)
You dont need to worry about WM_COMMAND. Yyou are simulating
mouse clicks. WM_COMMAND message is sent in response to menu item click.
You need to send mouse events (mouse_event) only.
Now when you send mouse event (lets say to open drop down
menu for "file"). Window takes some time to respond and create drop down
menu. Then you need to send another click on "SaveAs" item (lets say after
1/2 sec). So you will get the same behavior as user is clicking on the item.
As far as I know mouse_event wont set any error code. It will
just generate the input event. I recommend using mouse_event for moving the
mouse over the item you want to click later.
What I recommend is using mouse_event api with some sleeps
inbetween to give time windows to respond with window creation. So whatever
you are doing with physical mouse, you can do similar stuff with
mouse_event. You need to send the events accordingly.

Thanks,
Gagandeep Singh[MS]

Please do not send email directly to this alias. This alias is for
newsgroup purposes only.
This posting is provided "AS IS" with no warranties, and confers no rights.


0 new messages