Keypress logging on form not active

Speckled

Member
Joined
Feb 12, 2008
Messages
12
Programming Experience
1-3
Hi,

I have an app that minimizes to the system tray, I want it so if I press say F5 a message box appears (then I'll obviously add code to it etc).

I can get it to work while the form is active, but say I minimize it to system tray and press F5 nothing happens. Am I right in thinking the only way to get this to work is using 'keyboard hooking'? This looks pretty complicated.

So, for example, if I minimize my app, go onto Internet Explorer and press F5 I get a message box from my app to show on the screen.

How is this possible?

Any help appreciated. :)
 
You can use the standard system HotKey feature, see this post for a class you can easily add to your project to take advantage of this OS feature.
I forgot to add None=0 option to the HotkeyModifiers enumeration, so you can do this, or just use 0 as value when using the HotKey constructor.

F5 is a OS key, so you have to find a different, refer Windows Keyboard Shortcut Keys

There is a gotcha when hiding/showing form with system tray in that the forms handle is destroyed and new one created, so you can accomodate this by creating the Hotkeys instance and configure it in HandleCreated event and unregister in HandleDestroyed event. (a slight rewrite of the Hotkeys class is probably due :))
 
Back
Top