Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
479 views
in Technique[技术] by (71.8m points)

rdp - Alternative to SendKeys when running over Remote Desktop?

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...