5

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.

darx
  • 1,417
  • 1
  • 11
  • 25

1 Answers1

3

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).

Bedford
  • 1,136
  • 2
  • 12
  • 36
  • I tried, but it does not work with my keyboard (Logitech Illuminated Keyboard K740). Media Keys works normally with other media applications, but not with C# System.Windows.Forms.Keys.Media*. There's also no luck with any normal KeyEvent, C# just does not recognize my media keys. Only way I can handle media keys, is to override WndProc, and check for WM_APPCOMMAND, but with that I cannot get global hotkeys. Other ideas? – darx Sep 20 '14 at 21:11