Global keyhook for mediakeys in C#

770 Views Asked by At

With the following RegisterHotKey function, I can globally hook normal key-modifier combinations:

[DllImport("user32.dll")]
private static extern bool RegisterHotKey(IntPtr hWnd, int id, uint fsModifiers, uint vk);

Great article about it and full source code here: http://www.liensberger.it/web/blog/?p=207

But the question is, how do I hook Media Keys, those play/pause/next/previous -keys found in keyboards and pc remotes? I have googled and googled, but without any luck.

1

There are 1 best solutions below

1
On

Use the System.Windows.Forms.Keys.MediaPlayPause, System.Windows.Forms.Keys.Play, etc. values for the vk parameter (after casting it to uint) and 0 for the fsModifiers (unles you want to register for Shift-Play, Alt-Play or other key combinations).