Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to SendKeys when running over Remote Desktop?

Tags:

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?

like image 797
Cameron Avatar asked Jul 16 '09 16:07

Cameron


People also ask

How do I switch between Remote Desktop and local desktop using keyboard?

In this case, pressing WIN + CTRL + left/right keys would always switch desktops on the local computer, and there'd be some alternative hotkey to switch virtual desktops on the remote computer, such as WIN + CTRL + ALT + left/right.

How do you send Ctrl Alt Del in Remote Desktop?

While you are seeing the Remote Desktop window, simultaneously press the “CTRL,” “ALT,” and “END” keys on your keyboard. Instead of executing the standard CTRL-ALT-DEL command on your local computer, this command runs the command on the remote machine.

How do I press the Windows key in Remote Desktop?

Alt+Home—Pressing the Alt+Home keyboard combination with Remote Desktop displays the Start menu on the remote system. The Start menu gives you quick access to the different programs installed on the remote system. This key combination is the same as pressing the Windows key on your local desktop. 7.

Can you drag and drop in RDP?

Unfortunately, the answer to this question is NO. Remote Desktop, as a Windows built-in feature, allows people to remotely access a PC from another PC, which provides a large amount of convenience for many users. With Remote Desktop, we can not only realize file transfer by using copy and paste, but not drag and drop.


2 Answers

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:

  • Use SendMessage or SendInput for simple needs
  • Some good examples of how to use SendMessage can be found:
    • Send strings to another application by using Windows messages
    • SendMessage via pInvoke
    • How To Send Keystrokes To Extern Win Application
  • For more elaborate needs, it is recommended to use WCF
  • To get you started, read this Basic Tutorial that talks about Inter Process Communication

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")); 
like image 112
Mrchief Avatar answered Sep 20 '22 09:09

Mrchief


In my case I was successfully using WinAPI's SendInput with hardware scan codes. It seems like SendKeys maps chars to scan codes incorrectly.

like image 22
Vasily Nosov Avatar answered Sep 18 '22 09:09

Vasily Nosov