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();
}
}