Programatically send CTRL+C to remote desktop RRS feed

  • Question

  • Hello all,

    I am presently writing an application which incorporates a low level keyboard hook (hooked to the F12 key) to send the keys CTRL+C (copy) and then paste the copy into my application.

    I have run into a snag. Though the code I am using works on a local machine, when you connect to a remote desktop session it does not. Can anyone shed any light? I am just using


    To send the copy command. Any help appreciated.

    Tuesday, December 20, 2011 12:50 PM

All replies

  • I think its the problem with the sessions. Are you sure your application is running in the same session of the user ? You can't really use user32 functions across sessions.

    Tuesday, December 20, 2011 1:49 PM
  • Well thats the thing. My application is running on my local machine, I am just viewing the remote desktop window on one of my screens (I have two). If you manually press CTRL+C it works without issue but my SendKeys method doesn't work.
    Tuesday, December 20, 2011 1:54 PM
  • Hi SquidgeyBall,
    Welcome to the MSDN forum!

    Based on my research, SendKeys.SendWait only works for the active application. Are you sure that the application in the remote computer is the one that get focus?


    I suggest you try the SendMessage API instead.

    Please refer to the following link:

    1SendKeys is not a good fit mainly due to:

    1.1 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.

    1.2 RDP and many other libraries (DirectX e.g.) block them mainly due to security reasons.

    2. Better alternatives: Use SendMessage or SendInput for simple needs.

    2.1 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

    Sample code using SendMessage:

    HWND notepad = FindWindow(_T("Notepad"), NULL);
    HWND edit = FindWindowEx(notepad, NULL, _T("Edit"), NULL);
    SendMessage(edit, WM_SETTEXT, NULL, (LPARAM)_T("hello"));

    3. For more elaborate needs, it is recommended to use WCF. To get you started, read this Basic Tutorial that talks about Inter Process Communication.


    Please refer to the following thread at the same time:

    Issues with SendKeys

    Have a nice day!



    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Thursday, December 22, 2011 8:48 AM
  • Excellent response, thank you! I'll check out the links and mark your response as an answer if it all works out.
    Thursday, December 22, 2011 10:41 AM
  • Hi SquidgeyBall,

    How is it going with the problem currently?

    If you have any questions, please feel free to let us know.

    Have a nice day!

    Yoyo Jiang[MSFT]
    MSDN Community Support | Feedback to us
    Friday, December 30, 2011 9:01 AM
  • Hello Yoyo,

    My apologies for the late response.

    I took your advice and used the SendMessage API. It worked perfectly on a standard, local window (notepad, word etc) after editing your code to find the active window but unfortunately it did not work through the remote desktop.

    I'll have a look at the SendInput API to see if that does the trick.

    Thanks again for your help!


    Tuesday, January 3, 2012 9:12 AM
  • Check "NET SEND" command.

    You can PSEXEC command to start message service.


    Just a newbie for everything.
    Wednesday, January 4, 2012 9:36 AM
  • hi SquidgeyBall,

    Were you able to find a solution???
    Monday, January 28, 2013 4:25 PM