Send keystrokes for the SendMessage application (vb.net)

So far I have all the handle grabbing and gui setup. I'm at a standstill on how to complete the actual step.

I have this code:

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

I looked: http://msdn.microsoft.com/en-us/library/ms644950(VS.85).aspx and also http://msdn.microsoft.com/en-us/library/ms644927(v=VS .85) .aspx # system_defined

However, none of them gives much of the "code example" method that I need to learn how to do. I just need to send key events like pressing "/" or "w" etc. No, I can’t use the send keys for this.

Thanks if you can help!

+6
source share
2 answers

To simulate a keystroke, you will need to simulate the keydown and keyup event, which you will specify in the Msg field. (Use 256 for keydown and 257 for activation). wParam and lParam are message specific, so for keyup and keydown, wParam will have a key code ( see this page for hex codes), and lParam contains other different information ( see this page ). In vb.net you can use int32 for lParam. For example, you can use 0 for keydown and 65539 to activate keys.

Example:

 SendMessage(New IntPtr(CurrentHandle), 256, KEYCODE, 0) - Keydown SendMessage(New IntPtr(CurrentHandle), 257, KEYCODE, 65539) - Keyup 
+8
source

http://msdn.microsoft.com/en-us/library/ms644950(v=vs.85).aspx

 LRESULT WINAPI SendMessage( __in HWND hWnd, __in UINT Msg, __in WPARAM wParam, __in LPARAM lParam ); 

hWnd is the window handle for sending the message. Msg is the type of message to send. WParam and lParam are essentially "information." The exact use will depend on the message being sent.

What is your situation when you need to use SendMessage instead of SendKeys to emulate keys? I used to use SendMessage, but always was for mouse movements .. SendKeys () should send any keystroke that you specify in the active window.

 Public Shared Sub ActivateWin() Dim Win As Process = Process.GetProcessesByName("myWindow").First AppActivate(Win.Id) End Sub 

I used this above immediately before SendKeys (), and it always worked.

If this does not work or you want to use SendMessage to use SendMessage; The documentation for the WM_KEYDOWN message is what you need. http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx

You will manipulate the bits to create the correct lParam value.

+1
source

Source: https://habr.com/ru/post/885762/


All Articles