How do I take control of keyboard vol up, down and mute?
Posted: Sun Apr 21, 2019 10:16 am
I want to intercept the keyboard volume up, down and mute keys so that I can apply the effect directly in my program, which is particularly important for ASIO audio outputs. I can intercept these keys using a window callback, but I don't seem to be able to force Windows to subsequently ignore the action, even by returning 0 in the callback procedure. I need to be able to do this to avoid both my program and Windows applying volume up/down, which could double the effect (eg when using the default sound device). How can I tell Windows to ignore the volume up, down and mute keys?
Here's my test program:
Here's my test program:
Code: Select all
Procedure WinCallback(hWnd, uMsg, WParam, LParam)
Select uMsg
Case #WM_KEYDOWN
Debug "$" + Hex(uMsg) + ", #WM_KEYDOWN (" + #WM_KEYDOWN + "), VK=$" + Hex(wparam) + ", lparam=$" + Hex(lparam) + ", prev_key_state=" + Str((lparam & $40000000) >> 30)
ProcedureReturn 0
Case #WM_KEYUP
Debug "$" + Hex(uMsg) + ", #WM_KEYUP (" + #WM_KEYUP + "), VK=$" + Hex(wparam) + ", lparam=$" + Hex(lparam)
ProcedureReturn 0
Case #WM_SYSKEYDOWN
Debug "$" + Hex(uMsg) + ", #WM_SYSKEYDOWN, VK=$" + Hex(wparam) + ", lparam=$" + Hex(lparam) + ", prev_key_state=" + Str((lparam & $40000000) >> 30)
ProcedureReturn 0
Case #WM_SYSKEYUP
Debug "$" + Hex(uMsg) + ", #WM_SYSKEYUP, VK=$" + Hex(wparam) + ", lparam=$" + Hex(lparam)
ProcedureReturn 0
EndSelect
ProcedureReturn #PB_ProcessPureBasicEvents
EndProcedure
If OpenWindow(0, 50, 50, 400, 200, "Window Callback Test", #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget)
SetWindowCallback(@WinCallback(),0)
Repeat
Select WaitWindowEvent()
Case #PB_Event_CloseWindow
End
EndSelect
ForEver
EndIf