How to register a hotkey in your program
Posted: Sat Nov 24, 2007 7:17 am
Here is an example for how to register hotkeys to use within your program. Thanks to Trond for his example from another thread.
I'm reposting this under Tricks 'n' Tips because I think my example is a bit clearer. I've also fixed a bug.
To unset a hotkey register it again with the same modifier.
I'm reposting this under Tricks 'n' Tips because I think my example is a bit clearer. I've also fixed a bug.
To unset a hotkey register it again with the same modifier.
Code: Select all
Procedure HotKey(Key, Modifiers)
Static ID
If RegisterHotKey_(0, ID, Modifiers, Key) = 0
ProcedureReturn -1
EndIf
ID+1
ProcedureReturn ID-1
EndProcedure
Msg.MSG
hk1=HotKey(#VK_A,#MOD_CONTROL)
hk2=HotKey(#VK_S,#MOD_CONTROL)
hk3=HotKey(#VK_D,#MOD_CONTROL)
Repeat
GetMessage_(@Msg, 0, 0, 0)
If MSG\message = #WM_HOTKEY
Select MSG\wParam
Case hk1
Debug "Ctrl-A"
Case hk2
Debug "Ctrl-S"
Case hk3
Debug "Ctrl-D"
EndSelect
EndIf
ForEver