按键模拟失败,Windows 桌面被锁定
我有一个使用 Windows 输入模拟器 的应用程序。我用它来模拟父应用程序的 Ctrl-S 击键。当 Windows 桌面被锁定时,会引发异常
异常:CONTROL 的按键模拟不成功。 在 WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode keyCode) 在WindowsInput.InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode modifierKeyCode,VirtualKeyCode keyCode)
这是我的代码:
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_S);
InputSimulator.SimulateKeyDown(VirtualKeyCode.RETURN);
有什么想法吗?
I have an application that uses the Windows Input Simulator. I use this to simulate a Ctrl-S keystroke to the parent application. When the windows desktop is locked an exception is raised
Exception: The key down simulation for CONTROL was not successful.
at WindowsInput.InputSimulator.SimulateKeyDown(VirtualKeyCode keyCode)
at WindowsInput.InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode modifierKeyCode, VirtualKeyCode keyCode)
Here is my code :
InputSimulator.SimulateModifiedKeyStroke(VirtualKeyCode.CONTROL, VirtualKeyCode.VK_S);
InputSimulator.SimulateKeyDown(VirtualKeyCode.RETURN);
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
通过设计。计算机锁定时会激活安全桌面。它具有针对程序将击键插入用户名/密码文本框的对策。
您可以使用 SystemEvents.SessionSwitch 事件来检测计算机是否被锁定和解锁。没有记录的方法来检测机器当前是否已锁定,您只能看到转换。
By design. The secure desktop is activated when the machine is locked. Which has counter-measures against programs poking keystrokes into the username/password text boxes.
You can use the SystemEvents.SessionSwitch event to detect the machine getting locked and unlocked. There is no documented way to detect that the machine is currently locked, you can only see the transitions.
我可以想象,当 PC 被锁定时,Windows API 不会对此类内容做出反应。
I could imagine that it's the Windows API that doesn't react on this kind of stuff when the PC is locked.