Sending key “hangs” PC in C#

余生长醉 提交于 2019-12-03 16:35:49

I repro, Win7 and VS2008. That looks like a fairly nasty deadlock, you can get out of it by pressing Ctrl+Esc on the keyboard. By default, SendKeys uses a windows hook to inject the keys. Windows hooks can have fairly unpleasant side effects but I wouldn't hesitate to call this a Windows bug.

To fix it, use Project + Add New Item and select the Application Configuration File item template. Make it look like this:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <appSettings>
    <add key="SendKeys" value="SendInput"/>
  </appSettings>
</configuration>

If this is really meant to send a keystroke to your form then there are better ways to accomplish that.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!