0

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.

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);
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();
                }
        }
EylM
  • 5,967
  • 2
  • 16
  • 28
ObelixNL
  • 1
  • 1
  • Have you ever tried [`SendInput`](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-sendinput) after `SetForegroundWindow`? – Drake Wu Jul 12 '19 at 08:09
  • 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. – ObelixNL Jul 16 '19 at 14:40
  • 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. – ObelixNL Jul 16 '19 at 14:40

0 Answers0