我遇到以下问题,我想模拟从c#到应用程序的按键,我尝试使用sendkeys,inputsimulator&拦截。我的问题是如何处理这个?我知道sendkeys是一个非常小的类,但我希望它能在这种情况下解决,
Process p = Process.GetProcessesByName("condor").FirstOrDefault();
if (p != null)
{
IntPtr h = p.MainWindowHandle;
SetForegroundWindow(h);
SendKeys.Send("k");
}
这给了我错误:
SendKeys cannot run inside this application because the application is not handling Windows messages. Either change the application to handle messages, or use the SendKeys.SendWait method
我的问题是如何模拟按键到无形应用程序?
答案 0 :(得分:0)
欧文先生,美好的一天! 你应该在获得MainWindowHandle之前尝试添加Thread.Sleep。