title: Send keyboard strokes to an RemoteApp application within an Remote Desktop session with Winforms C#
body: <p>I want to send keyboard keys to an RemoteApp application. I am using C# with the Windows API.</p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>On a Windows 2019 Server with Remote Desktop it works great, however with versions 2012 and 2016 it doesn’t work.</p>
  
  <p>I’ve also tried the following:
  SendMessage and PostMessage with the handle and WM_KEYDOWN / WM_KEYUP.</p>
  
  <pre><code>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);
  </code></pre>
  
  <pre><code>foreach (KeyValuePair&lt;IntPtr, string&gt; 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();
                  }
          }
  </code></pre>