delphi send key into an invisible process [duplicate]
The goal is to send the Q key press to an invisible process (that does not have focus) : I know the process ID.
I know how to send keys to a visible application. Can this be done to an hidden application ?
I assume, that your invisible process has a window, which just happen to be invisible (it could for example have been hidden through a call to ShowWindow with SW_HIDE als parameter) and that you want to send keystrokes using SendMessage/PostMessage.
I would suggest to try the following:
- Enumerate all main windows using EnumWindows.
- For each window check if it belongs to your process using GetWindowThreadProcessId.
- As soon as you have found the main window of your process, send your Keystrokes using SendMessage or PostMessage.
A hidden window should be able to receive keystokes as good as a visible window and most application probably don't check if they are really visible before reacting, so that there are good chances that it works.
精彩评论