如何限制鼠标和键盘操作
如何限制鼠标和键盘操作? 我想实现当我的程序运行时不再允许对键盘和鼠标进行操作,程序运行完后再恢复正常操作。谢谢大家
'模块代码 Option Explicit Public Declare Function SetWindowsHookEx Lib "user32" Alias "SetWindowsHookExA" (ByVal idHook As Long, ByVal lpfn As Long, ByVal hmod As Long, ByVal dwThreadId As Long) As Long Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long Public Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Any) As Long Public Const WH_KEYBOARD = 2 Public Const WH_KEYBOARD_LL = 13 Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long) Public hHook As Long Type tagKBDLLHOOKSTRUCT vkCode As Integer scanCode As Integer flags As Long Time As Long dwExtraInfo As Long End Type Sub EnableHook() '设置拦截 hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf Myfunc, App.hInstance, 0) End Sub Sub DisableHook() Dim ret As Long ret = UnhookWindowsHookEx(hHook) '取消拦截 End Sub Function Myfunc(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long 'wParam代表按键 Dim kk As tagKBDLLHOOKSTRUCT Dim kb As Long, pks As Byte CopyMemory kk, lParam, Len(kk) Myfunc = 1: Exit Function Myfunc = CallNextHookEx(hHook, ncode, wParam, lParam) '传到下一个拦截 End Function '窗体代码 Option Explicit Private Sub Form_Load() Call EnableHook End Sub Private Sub Form_Unload(Cancel As Integer) Call DisableHook End Sub