Vb.net – Sending an application keystrokes with “SendMessage” (vb.net)

keystrokessendmessagevb.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!

Best Answer

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
Related Topic