最小化时检测按键和托盘图标
对于我的测试,我用 C# 创建了一个小程序,用以下代码来检测按键:
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.F12) MessageBox.Show("f12 pressed");
}
当表单聚焦且处于活动状态时,此方法可以正常工作。我花了很多时间寻找如何在最小化时将其设置为工作,我在这里找到了添加系统托盘图标的解决方案。我遵循了解决方案,但不再起作用了。
当我最小化它时,图标托盘出现并工作,但我没有检测到按键。
For my test I've created a little program in C# to detect key presses with this code:
protected override void OnKeyDown(KeyEventArgs e)
{
if (e.KeyCode == Keys.F12) MessageBox.Show("f12 pressed");
}
This works fine when the form is focused and active. I've spent many time to find how to set it for works when minimized, I found a solution here to add system tray icon. I followed solution but didn't work anymore.
When i minimize it, the icon tray appears and works, but i didn't detect key presses.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的表单仅在获得焦点时才会接收按键事件,要接收其他按键事件,您需要注册全局热键。
http://www.dreamincode.net/forums/topic/180436-global-热键/
Your form will only receive keypress events when it has focus, to receive other keypress events you would need to register a global hotkey.
http://www.dreamincode.net/forums/topic/180436-global-hotkeys/