tags:

views:

881

answers:

3

I need to be able to set up a background hotkey event for a WPF application. (by background I mean that the application in question might not necessary be in focus).

I know that with WinForms the proper way of doing it would be to import user32.dll, and use RegisterHotKey, and the catch the appropriate WM_POST message. I'm convinced that there has to be a better solution with WPF, then using user32.dll, but I have been unable to find anything. Any suggestions? Thanks

+1  A: 

I don't think WPF has any built in support for hotkeys, at least I couldn't find any and I used RegisterHotKey directly.

Nir
Agreed, seems like RegisterHotKeys is the only solution.
vicjugador
A: 

Why not using Commanding infrastructure provided by WPF? You could try assigning some command bindings for you main window and provide some key gestures for it...

Denis Vuyka
+1  A: 

This has an excellent example (see 5.2 "Registering the System Hotkey"):

http://blog.280z28.org/archives/2007/03/15/

It uses the Managed Windows API, which is a great wrapper around a lot of the legacy api calls.

James Sulak