Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending an application keystrokes with "SendMessage" (vb.net)

So far, I have all the handle capturing and gui set up. I'm stumped as to how to perform the actual step.

I have this code:

SendMessage(New IntPtr(CurrentHandle), WHAT,GOES,HERE?)

I've been looking at: http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx and http://msdn.microsoft.com/en-us/library/ms644927(v=VS.85).aspx#system_defined

However, none of these are giving much of the "code example" method that I need to learn how to do it. I just need to send key events such as pressing "/" or "w", etc. No, I can't use sendkeys for this.

Thanks if you can help!

like image 630
Freesnöw Avatar asked Apr 12 '11 21:04

Freesnöw


1 Answers

To simulate a keypress, you would need to simulate a keydown and keyup event, which would be what you specify in the Msg field. (Use 256 for keydown and 257 for keyup). wParam and lParam are message-specific, so for keyup and keydown, wParam would be the key code (See this page for the hexadecimal codes) and lParam contains other miscellaneous information (see this page). In vb.net you can use an int32 for lParam. For example, you can use 0 for keydown and 65539 for keyup.

Ex:

SendMessage(New IntPtr(CurrentHandle), 256, KEYCODE, 0) - Keydown
SendMessage(New IntPtr(CurrentHandle), 257, KEYCODE, 65539) - Keyup
like image 185
GregoryComer Avatar answered Sep 26 '22 07:09

GregoryComer