I can't understand how to use SendMessage or PostMessage calls

前端 未结 5 782
南方客
南方客 2020-12-29 14:39

I need to simulate a keypress in a third party application. Let\'s say I have a C# application that needs to send an \"8\" to the Calculator application. I can\'t use the Se

5条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2020-12-29 14:53

    There is a good article about this on CodeProject: http://www.codeproject.com/KB/cs/SendKeys.aspx

    SendKeys is actually the correct idea, but you need to get the HWND (window handle) of the target window. This MSDN sample shows how to use SendKeys effectively, but not how to discover the HWND of anything other than the top-most window.

    Combine the two techniques, using the CodeProject example to locate the HWND of the application you want to target, then use the MSDN article to use SendKeys to send the key strokes (or mouse events) to the target application.

提交回复
热议问题