C# and SendMessage (keys) is not working

前端 未结 1 1384
鱼传尺愫
鱼传尺愫 2021-01-19 06:16

I tried to send a key to an application. For an easy test I just used notepad. That\'s what the code looks like:

[DllImport(\"USER32.DLL\", EntryPoint = \"Se         


        
相关标签:
1条回答
  • 2021-01-19 06:52

    Several problems:

    • Your declaration is wrong, the last 2 parameters are IntPtr, not int
    • You should use PostMessage, not SendMessage
    • You are sending to the wrong window. The edit window of Notepad is a child window
    • You are forgetting to send WM_KEYUP
    • The actual letter you get will depend on the state of the Shift key

    The neck shot: Vista and Win7 UIPI (User Interface Privilege Isolation) prevents a restricted process from injecting messages into an elevated process.

    0 讨论(0)
提交回复
热议问题