Click here to Skip to main content
15,917,628 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
See more:
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
	}
}

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.
Posted
Updated 4-Feb-10 6:08am
v2

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[^].
 
Share this answer
 
AFAIK, you'd use a hook for that; a normal Windows-application might not handle keyboardmessages if it doesn't have the focus.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900