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

后端 未结 2 417
孤独总比滥情好
孤独总比滥情好 2020-12-09 06:46

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(         


        
2条回答
  •  再見小時候
    2020-12-09 07:23

    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 handle of the window to send the message. Msg - is the message type to send. WParam and lParam are essentially 'information'. The exact use will depend on the message you are sending.

    What situation are you in that you need to use SendMessage instead of SendKeys to emulate keypresses? I've used SendMessage before, but it's always been for mouse movements. .SendKeys() should send whatever keystroke you tell it to the active window.

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

    I've used the above immediately before SendKeys() and it's always worked.

    If that doesn't work, or you want to use SendMessage for the sake of using SendMessage; the documentation for WM_KEYDOWN message is what you need. http://msdn.microsoft.com/en-us/library/ms646280(v=vs.85).aspx

    You'll be manipulating bits to create the correct lParam value.

提交回复
热议问题