Option ExplicitDeclare Function SetWindowsHookEx Lib "user32" Alias _ "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, _ByVal hmod As Long, ByVal dwThreadId As Long) As LongDeclare Function UnhookWindowsHookEx Lib "user32" _ (ByVal hHook As Long) As LongDeclare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, _ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As LongPublic hnexthookproc As LongPublic Const HC_ACTION = 0Public Const WH_KEYBOARD = 2Public Sub UnHookKBD () If hnexthookproc <> 0 ThenUnhookWindowsHookEx hnexthookprochnexthookproc = 0End IfEnd SubPublic Function EnableKBDHook () If hnexthookproc <> 0 ThenExit FunctionEnd Ifhnexthookproc = SetWindowsHookEx (WH_KEYBOARD, AddressOf _MyKBHFunc, App.hInstance, 0) If hnexthookproc <> 0 ThenEnableKBDHook = hnexthookprocEnd IfEnd FunctionPublic Function MyKBHFunc (ByVal iCode As Long, _ByVal WPAram as long, Byval LParam as long) As long 'This parameter is fixed, can not move, and mykbhfunc name as long as the name after addressof in' setWindowsHookex (), not necessarily What 'WPARAM is incoming, which key code, who is pushing, if you put the following two lines unmark, all keyboard inputs do not work,' mykbhfunc = 1 'Eat messages' exit functionmykbhfunc = 0' message To process IF iCode <0 ThenMyKBHFunc = CallNextHookEx (hnexthookproc, iCode, wParam, lParam) Exit FunctionEnd IfIf wParam = vbKeySnapshot then 'detected to have no press PrintScreen key MyKBHFunc = 1' then this eaten Hook this message Debug.Print "haha" ElseCall CallNextHookEx (hnexthookproc, iCode, wParam, lParam) End IfEnd Function 'in the following FormPrivate Sub Form_Load () Call EnableKBDHookEnd SubPrivate Sub Form_Unload (Cancel As Integer) Call UnHookKBDEnd Sub