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

前端 未结 2 1967
忘掉有多难
忘掉有多难 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:56

    You may be able to figure out the lpszClass of the program using an inspection tool such as WinSpy++. It gives you a crosshair that you can drag and position over the desired control. This was able to easily provide me with the "edit" class name for notepad.

    If things aren't working, click the "More>>" button in the lower right of WinSpy++, then click the "Locate" button to view the control hierarchy; you may need to post the WM_KEYDOWN message to one of the parent or child controls instead.

提交回复
热议问题