RegisterHotKey
Register a system wide hot key
AI
AI Summary: This codebase represents a historical implementation of the logic described in the metadata. Our preservation engine analyzes the structure to provide context for modern developers.
Source Code
'This example uses the MsgHook OCX but any similar OCX would also work
'iAtom stores the id used by the hotkey. If you have more then one hot key, use one atom for each
Dim iAtom As Integer
Private Sub Form_Load()
Dim res As Long
'Get a value for atom
iAtom = GlobalAddAtom("MyHotKey")
'Register the Ctrl-Alt-T key combination as the hotkey
res = RegisterHotKey(Me.hwnd, iAtom, MOD_ALT + MOD_CTRL, vbKeyT)
'Setup msghook to receive the WM_HOTKEY message
Msghook1.HwndHook = Me.hwnd
Msghook1.Message(WM_HOTKEY) = True
End Sub
Private Sub Form_Unload(Cancel As Integer)
Dim res As Long
'Remove the hotkey and delete the atom
res = UnregisterHotKey(Me.hwnd, iAtom)
res = GlobalDeleteAtom(iAtom)
End Sub
Private Sub Msghook1_Message(ByVal msg As Long, ByVal wp As Long, ByVal lp As Long, result As Long)
If msg = WM_HOTKEY Then
If wp = iAtom Then
'Do your thang...
MsgBox "Boing!!!"
End If
End If
Msghook1.InvokeWindowProc msg, wp, lp
End Sub
Upload
Original Comments (3)
Recovered from Wayback Machine