1

is it possible to detect which keys are used for a system volume accelerator in win32 using c++? For example: if the user presses fn + key up (and this is also the key combination to change the system volume), i would like to detect this event and response to it.

blejzz
  • 3,349
  • 4
  • 39
  • 60

3 Answers3

3

This is handled by the machine's BIOS. It produces a keystroke, VK_VOLUME_DOWN or VK_VOLUME_UP virtual key. DefWindowProc handling of that WM_KEYDOWN message produces WM_APPCOMMAND, APPCOMMAND_VOLUME_UP/DOWN. DefWindowProc handling of that message adjusts the volume.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • Actually, `DefWindowProc` handling of that message forwards `WM_APPCOMMAND` to Explorer, and Explorer adjusts the volume. If you want to override the volume buttons in your app, respond to the `WM_APPCOMMAND` message. – Raymond Chen Oct 01 '11 at 14:10
  • @Raymond - aren't you going too fast? DefWindowProc handling of WM_APPCOMMAND on a toplevel window invokes the shell hook afaik. If WM_KEYDOWN handling sends WM_APPCOMMAND straight to Explorer then there's no way to respond to it. – Hans Passant Oct 01 '11 at 14:22
  • Yeah, the `WM_APPCOMMAND` goes to Explorer via a shell hook. The point was that it's Explorer that changes the volume, not `DefWindowProc`. The distinction is not significant to this question, but it affects similar questions. – Raymond Chen Oct 01 '11 at 17:06
  • but the messages WM_APPCOMMAND and WM_KEYDOWN are sent only when the application has focus. How can i detect this keys even if the application doesn't have focus? – blejzz Oct 12 '11 at 10:34
0

I don't think this is possible generally. The fn-keys are usually handled by the BIOS-SMM-ACPI whatever, and that is not accesible to user programs.

Maybe, if it were translated to the standard multimedia volume-up key, you could get that, but I wouldn't bet on it.

rodrigo
  • 94,151
  • 12
  • 143
  • 190
0

see this post... http://www.rohitab.com/discuss/topic/21252-change-volume/

YAHOOOOO
  • 939
  • 4
  • 19
  • 27
  • The OP is asked how to detect keypresses that lead to system volume changes, not how to modify the system volume. – In silico Oct 01 '11 at 12:36