1

我正在使用InputSimulator向活动 Windows 发送击键 (ctrl+c) 为了实现这一点,我将自己的表单最小化,并使用 WIN32 API 和 SetForegroundWindow 设置我希望将密钥发送到前台的应用程序。现在这一切都适用于大多数应用程序。但是,例如,我遇到了 Windows Mail 应用程序的问题。在发送 keycombo 之前,GetForegroundwindow 向我保证邮件应用程序确实处于活动状态。但是不执行复制命令。如果我在发送命令之前等待 1-2 秒(使用 Thread.sleep),它就可以工作。有谁知道如何解决这个问题?

使我的表单处于非活动状态

this.Hide();
this.WindowState = FormWindowState.Minimized; //this seem to be the most reliable way

设置前景和按键

if (foreGroundHandle != null && foreGroundHandle != IntPtr.Zero)
SetForegroundWindow(foreGroundHandle);

new InputSimulator().Keyboard.ModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_C);
4

0 回答 0