[Name] Add system hotkey
[Language Type] Visual Basic
[Category 1] System Control
[Category 2] VBAPI
[Category 3] underlying development
[Data Source] Shawls
[Save time] 2002-08-19
[Keyword one] hotkey
[Keyword 2] system
[Keyword three] hook
[Introduction] Empty
[Source code content]
Option expedition
Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As IntegerPrivate Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal ipfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As LongPrivate Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As LongPrivate Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As LongPrivate Const WH_KEYBOARD = 2
Private HHOOK As Longprivate Boolkeyup as Boolean
Public sub enablehook () hhook = setwindowshookex (wh_keyboard, addressof keyfun, app.hinstance, 0) End Sub
Public Sub Disablehook () UnHookWindowsHookex (HHOOK) End Sub
Function KeyFun (ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long'If (GetKeyState (& H10) And & HF0000000) Then 'shift keySelect Case wParam Case vbKeyF If boolKeyUp = True Then boolKeyUp = False MsgBox "f" Else boolKeyUp = True End If KeyFun = 1 Exit Function Case vbKeyG If boolKeyUp = True Then boolKeyUp = False MsgBox "g" Else boolKeyUp = True End If KeyFun = 1 Exit FunctionEnd Select'End IfKeyFun = CallNextHookEx (hHook, ncode, wParam, lParam ) End function