none
Send keyboard strokes to an RemoteApp application within an Remote Desktop session with Winforms C# RRS feed

  • Question

  • I want to send keyboard keys to an RemoteApp application. I am using C# with the Windows API.

    The code example works when I am using Windows 10 Desktop with an RemoteApp application. The application appears in the foreground and the shortcut code CTRL + SHIFT + O is executed in the application.

    When I start the same application on a Windows Server 2012 / 2016 Remote Desktop server in an RDS session it will set the window to the foreground but the application is not receiving the shortcut.

    On a Windows 2019 Server with Remote Desktop it works great, however with versions 2012 and 2016 it doesn’t work.

    I’ve also tried the following:
    SendMessage and PostMessage with the handle and WM_KEYDOWN / WM_KEYUP.

    Example:

    Class.WinAPI.PostMessage(handle,WM_KEYDOWN,0x11,0);
    Class.WinAPI.PostMessage(handle,WM_KEYDOWN,0x10,0);
    Class.WinAPI.PostMessage(handle,WM_KEYDOWN,0x4F,0);
    Class.WinAPI.PostMessage(handle,WM_KEYUP,0x11,0);
    Class.WinAPI.PostMessage(handle,WM_KEYUP,0x10,0);
    Class.WinAPI.PostMessage(handle,WM_KEYUP,0x4F,0);

    Example SendInput:

    var sim = new InputSimulator();
    // send with ModifiedKeyStroke
                        sim.Keyboard.ModifiedKeyStroke(
                            new[] { VirtualKeyCode.LCONTROL, VirtualKeyCode.LSHIFT, VirtualKeyCode.VK_O },
                            VirtualKeyCode.VK_L
                        );
    
                        Thread.Sleep(2500);
    // send with KeyPress
                        sim.Keyboard.KeyPress(new[] { VirtualKeyCode.LCONTROL, VirtualKeyCode.LSHIFT, VirtualKeyCode.VK_O });

    Example focus application:

    foreach (KeyValuePair<IntPtr, string> window in OpenWindowGetter.GetOpenWindows())
                {
                    IntPtr handle = window.Key;
                    string title = window.Value;
                    if (title.ToLower().Contains(“ApplicationName”))
                    {
                        Class.WinAPI.SetForegroundWindow(handle);
                        Thread.Sleep(1);
                        SendKeys.SendWait("^+O");
                        Thread.Sleep(1);
                        SendKeys.Flush();
                    }
            }


    Thursday, July 11, 2019 1:31 PM

All replies

  • Hi ObelixNL,

    Thank you for posting here.

    For your question, I want to know what your remote app is. 

    Could you provide a full code about your problem or upload a simple project to our forum?

    It will help us to solve your problem better.

    We are waiting for your update.

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 12, 2019 9:13 AM
    Moderator
  • Hello,

    I have created an Github repo on https://github.com/steffjenl/sendinput-remoteapp

    RemoteAppClient is the client on the RemoteApp server, you can open a popup screen with CTRL + SHIFT + O and enter a text in the input field. When you clicked on the button it will return an MessageBox.

    RemoteDesktopServer is the application witch search the RemoteAppClient RAILWINDOW and send input with SendInput. I have used WindowsInput package to send the keystrokes. In de background WindowsInput use SendInput.

    RemoteAppClient can be runned on Windows 2012 R2 or higher.

    When RemoteDesktopServer is started on Windows Server 2012 R2 / Windows Server 2016, he can find the window, only the SendInput is not received. 

    When RemoteDesktopServer is started on Windows Server 2019, he can find the window, shows the popup screen, send the test text and shows the MessageBox.



    • Edited by ObelixNL Monday, July 15, 2019 7:43 AM
    Monday, July 15, 2019 7:42 AM
  • Hi ObelixNL,

    Thanks for the feedback.

    Based on my test, I get the same result from Windows Server 2016 and Windows 10.

    In Windows 10

    In windows server 2012,

    I could not reproduce your problem, so I suggest that you could report a problem in the following link.

    https://developercommunity.visualstudio.com/spaces/8/index.html

    Best Regards,

    Jack


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, July 17, 2019 9:13 AM
    Moderator
  • Do you start the client as an RemoteApp application? and not directly from the remote desktop server?
    Wednesday, July 17, 2019 9:27 AM