Alternative to SendKeys when running over Remote Desktop

rdpremote-desktopsendkeys

I have an application which injects keystrokes into applications via SendKeys.

Unfortunately, the application will not work when I am running it via Remote Desktop
because of the well known issue that SendKeys doesn't work with Remote Desktop.

Has anyone solved this issue before, or have any good suggestions on how to resolve it?

Best Solution

SendKeys is not a good fit mainly due to:

  • It can only send keys to active/focused application, which is never guaranteed to work because the the active application can change between the time the keys are actually sent.
  • RDP and many other libraries (e.g., DirectX) block them mainly for security reasons.

Better alternatives:

Sample code using SendMessage:

HWND hwndNotepad = FindWindow(_T("Notepad"), NULL);
HWND hwndEdit = FindWindowEx(hwndNotepad, NULL, _T("Edit"), NULL);
SendMessage(hwndEdit, WM_SETTEXT, NULL, (LPARAM)_T("hello"));
Related Question