vb屏蔽ctrl等系统键
如题,我知道能用下面这个代码屏蔽alt+tab键PrivateConstMOD_ALT=&H1PrivateDeclareFunctionRegisterHotKeyLi...
如题,我知道能用下面这个代码屏蔽alt+tab键Private Const MOD_ALT = &H1
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As LongPrivate Sub Form_Load()
Me.Caption = RegisterHotKey(Me.hwnd, 1, MOD_ALT, vbKeyTab)
End Sub能不能用同类的方法屏蔽掉其他的系统按键ctrl,shift,esc我知道挂钩,但是不知道要怎么用,谁能帮忙下 展开
Private Declare Function RegisterHotKey Lib "user32" (ByVal hwnd As Long, ByVal id As Long, ByVal fsModifiers As Long, ByVal vk As Long) As LongPrivate Sub Form_Load()
Me.Caption = RegisterHotKey(Me.hwnd, 1, MOD_ALT, vbKeyTab)
End Sub能不能用同类的方法屏蔽掉其他的系统按键ctrl,shift,esc我知道挂钩,但是不知道要怎么用,谁能帮忙下 展开
1个回答
2013-08-02
展开全部
'模块---------------------------------------------------------Option Explicit
Public hHook As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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 CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Dim p As KBDLLHOOKSTRUCT
Public Function MyKBHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pbj As Boolean
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
pbj = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93)) Or (p.vkCode = &H73)
End If
End If
If pbj Then
MyKBHook = -1
Else
MyKBHook = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End FunctionPublic Function Hook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pbj As Boolean
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
pbj = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93)) Or (p.vkCode = &H73)
End If
End If
Hook = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End Function'窗体Private Sub Command1_Click()
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf MyKBHook, App.hInstance, 0) '屏蔽组合热键
End SubPrivate Sub Command2_Click()
UnhookWindowsHookEx hHook'解除屏蔽
End Sub'---------------------因为ctrl+ait+del特殊无法用此f方法屏蔽,但可用Open Environ$("WinDir") & "\system32\taskmgr.exe" For Random Lock Read As #100 '屏蔽CTRL+ALT+DEL(XP可行)
Close#100 '解除屏蔽
Public hHook As Long
Public Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
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 CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Public Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Public Const HC_ACTION = 0
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const WH_KEYBOARD_LL = 13
Public Const LLKHF_ALTDOWN = &H20
Public Type KBDLLHOOKSTRUCT
vkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Dim p As KBDLLHOOKSTRUCT
Public Function MyKBHook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pbj As Boolean
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
pbj = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93)) Or (p.vkCode = &H73)
End If
End If
If pbj Then
MyKBHook = -1
Else
MyKBHook = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End FunctionPublic Function Hook(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim pbj As Boolean
If (nCode = HC_ACTION) Then
If wParam = WM_KEYDOWN Or wParam = WM_SYSKEYDOWN Or wParam = WM_KEYUP Or wParam = WM_SYSKEYUP Then
CopyMemory p, ByVal lParam, Len(p)
pbj = _
((p.vkCode = VK_TAB) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((p.flags And LLKHF_ALTDOWN) <> 0)) Or _
((p.vkCode = VK_ESCAPE) And ((GetKeyState(VK_CONTROL) And &H8000) <> 0)) Or _
((p.vkCode = 91) Or (p.vkCode = 92) Or (p.vkCode = 93)) Or (p.vkCode = &H73)
End If
End If
Hook = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End Function'窗体Private Sub Command1_Click()
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf MyKBHook, App.hInstance, 0) '屏蔽组合热键
End SubPrivate Sub Command2_Click()
UnhookWindowsHookEx hHook'解除屏蔽
End Sub'---------------------因为ctrl+ait+del特殊无法用此f方法屏蔽,但可用Open Environ$("WinDir") & "\system32\taskmgr.exe" For Random Lock Read As #100 '屏蔽CTRL+ALT+DEL(XP可行)
Close#100 '解除屏蔽
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询