当应用程序最小化或在后台时,检测按键按下/按下事件 [英] Detect a key-down/up event when application is minimized or in background
问题描述
你好.
我试图使应用程序在最小化为系统托盘时检测按键.
如果我有
Hi there.
I''m trying to make my application detect keypresses when minimized to systray.
If I have
BOOL CTestMFC::PreTranslateMessage(MSG* pMsg) {
if(pMsg->message == WM_KEYDOWN) {
// Keydown detected
}
}
它只会在我按一个键并且应用程序在前台时通知.但我想知道用户何时始终按下特定按钮,即使其他全屏程序正在运行.
帮助将不胜感激.
答案后
是的,该应用程序有点像Ventrilo/Teamspeak,所以我需要知道何时按下通话"按钮.
我将查看链接并尝试解决我的问题. =)
谢谢大家,我很感激.
亲切的问候.
it''ll only notify when I press a key and the application is in the foreground. But I''d like to know when a user presses a specific button at all time, even though other fullscreen-programs are running.
Help would be appreciated.
Edit after answer:
Yes, the application is kindof like Ventrilo/Teamspeak, so I need to know when the ''talk'' button has been pressed.
I''ll look at the links and try to fix my problem. =)
Thanks guys, I appreciate it.
Kind Regards.
推荐答案
在Windows中,按键属于具有焦点的窗口.如果您的应用没有重点关注-就像您的情况一样-它们不是您的关注对象,通常不会告诉您有关它们的信息.
如您所说,如果确实需要了解它们,则必须建立Windows挂钩并提供将为此类事件调用的回调函数.有关更多信息,请参见此处 [此处 [ ^ ].
In Windows, key presses belong to the window that has focus. If your app doesn''t have focus - as is your situation - they aren''t yours and you normally are never told about them.
If, as you say, you do need to know about them, you have to establish a Windows hook and provide a callback function that will be called for such events. For more information see here[^] and here[^].
AFAIK,您可以为此使用钩子;如果没有焦点,普通的Windows应用程序可能无法处理键盘消息.
AFAIK, you''d use a hook for that; a normal Windows-application might not handle keyboardmessages if it doesn''t have the focus.
这篇关于当应用程序最小化或在后台时,检测按键按下/按下事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!