Vb.net – 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:

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 Solution

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.


SendMessage(New IntPtr(CurrentHandle), 256, KEYCODE, 0) - Keydown
SendMessage(New IntPtr(CurrentHandle), 257, KEYCODE, 65539) - Keyup
Related Question