Send Keystrokes to a program even if its in background using c#

前端 未结 2 1959
忘掉有多难
忘掉有多难 2020-12-15 13:34

I wanna send key stroke to a program even if it is running in background. But I can do this only for NOTEPAD like this,

[DllImport(\"user32.dll\")]
protecte         


        
2条回答
  •  心在旅途
    2020-12-15 13:53

    I think you'll need to have the background program install a low-level keyboard hook via the win32 function SetWindowsHookEx().

    Here's the MSDN documentation for SetWindowsHookEX()

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

    And here's the KB article on how to do it from C#

    http://support.microsoft.com/kb/318804

    This article goes into some detail, too: http://www.codeguru.com/columns/vb/article.php/c4829

    I expect your app will get caught by various spyware/anti-virus software as a keyboard logger, though.

    Good luck.

提交回复
热议问题