当应用程序未处于焦点时响应事件
我在编写一个我想要始终处于活动状态的程序时遇到了困难。
我在 keydown 上编写了代码来执行某些操作,但是当 form1
最小化或在托盘中时 keydown 事件没有响应。即使应用程序未处于焦点状态,如何才能使应用程序响应键盘事件?
另外:
它的窗口应用程序,lang是c#.NET,
I am having trouble writing a program that I want to be active always.
I wrote code on keydown to do something, but when form1
is minimized or in tray keydown event does not response. How can I get my application to respond to keyboard events even when it is not in focus?
addition :
its window app , and lang is c#.NET ,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果我可以假设该程序适用于 Windows,那么您就不能这样做。一旦您的应用程序窗口关闭,它就不会引发 KeyUp/KeyDown。最接近您想要的是热键(一旦检测到特定键即可激活程序)或键盘挂钩(如果您希望概述每个按键)。
但是,您将使用什么取决于您正在考虑的具体场景。
If I can assume that this program is for Windows, you cannot do that. Once you application window is closed, it will not raise KeyUp/KeyDown. Nearest to what you want is either hotkeys (to activate program once specific key is detected) or keyboard hook (if you wish to have overview of every key press).
However, what you will use depends on which exact scenario were you thinking about.