我想将键盘键发送到 RemoteApp 应用程序。我将 C# 与 Windows API 一起使用。
当我将 Windows 10 桌面与 RemoteApp 应用程序一起使用时,该代码示例有效。应用程序出现在前台,并在应用程序中执行快捷键 CTRL + SHIFT + O。
当我在 RDS 会话中的 Windows Server 2012 / 2016 远程桌面服务器上启动相同的应用程序时,它会将窗口设置为前台,但应用程序没有收到快捷方式。
在带有远程桌面的 Windows 2019 服务器上,它运行良好,但对于 2012 和 2016 版本,它不起作用。
我还尝试了以下方法:带有句柄和 WM_KEYDOWN / WM_KEYUP 的 SendMessage 和 PostMessage。
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();
}
}