繁体   English   中英

C#中的SendKeys-无法发送多个密钥

[英]SendKeys in c# - not able to send multiple keys

我实际上是通过C#代码激活VB应用程序的按钮单击事件-我已经创建了按钮单击的快捷键,并在以下代码的帮助下进行了调用。

该代码工作正常,但未触发按钮2单击事件。

1.Step-调用VB项目的button1的Click事件

  ProcessStartInfo startInfo = new ProcessStartInfo();
  startInfo.FileName = @"C:\New\MyProj.exe";
  Process process = Process.Start(startInfo);
  IntPtr h = process.MainWindowHandle;
  SetForegroundWindow(h);
  // Send it Alt-X
  SendKeys.SendWait("%x");
  Thread.Sleep(30000);

2.Step-调用一个蝙蝠文件

  Process process1 = null;
  ProcessStartInfo startInfo1 = new ProcessStartInfo();
  startInfo1.FileName = @"C:\App\Test.bat";
  process1 = Process.Start(startInfo1);
  Thread.Sleep(10000);

3.Step-调用VB项目的button2的Click事件

   //again i am setting main window as my VB project and calling another click event.
   SetForegroundWindow(h);
   SendKeys.SendWait("%h");
   Thread.Sleep(10000);

最终点击事件无效,为什么? -Alt + h不触发

尝试使用process.kill()杀死第一个进程,然后通过以下方式再次启动VB项目:

   startInfo = new ProcessStartInfo();
   startInfo.FileName = @"C:\New\MyProj.exe";
   Process process = Process.Start(startInfo);
   process.WaitForInputIdle();
   SetForegroundWindow(h);
   SendKeys.SendWait("%h");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM