vb屏蔽键盘上部分键
1、我要能够同时屏蔽win,alt+f4,ctrl+alt+f4的源码2、如果1实现了,如何进一步屏蔽各种组合键我已将鼠标限制在一个窗口内了,通过输入密码解除锁定如何屏蔽...
1、我要能够同时屏蔽win,alt+f4,ctrl+alt+f4的源码
2、如果1实现了,如何进一步屏蔽各种组合键
我已将鼠标限制在一个窗口内了,通过输入密码解除锁定
如何屏蔽ctrl+alt+delete 展开
2、如果1实现了,如何进一步屏蔽各种组合键
我已将鼠标限制在一个窗口内了,通过输入密码解除锁定
如何屏蔽ctrl+alt+delete 展开
展开全部
分二步:
1、建立一个模块,然后复制下面代码
Option Explicit
Private 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 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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Type KEYMSGS
vKey As Long
sKey As Long
flag As Long
time As Long
End Type
Public Const WH_KEYBOARD_LL = 13
Public Const VK_LWIN = &H5B
Public Const VK_RWIN = &H5C
Public Const HC_ACTION = 0
Public Const HC_SYSMODALOFF = 5
Public Const HC_SYSMODALON = 4
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public P As KEYMSGS
Public lHook As Long
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke 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)
Select Case P.vKey
Case vbKeyF4
If (GetKeyState(vbKeyMenu) And &H8000) <> 0 Then '如果按了Alt+F4键
fEatKeystroke = True '就吃了
End If
End Select
End If
End If
If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
2、在Form中程序调用如下:
Private Sub Form_Load()
lHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)'设置键盘勾子
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx lHook''取消键盘勾子
End Sub
稍微进一步修改,你可以的吧……
屏蔽F4 和 WIN 就可以了
1、建立一个模块,然后复制下面代码
Option Explicit
Private 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 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 Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (lpvDest As Any, ByVal lpvSource As Long, ByVal cbCopy As Long)
Public Type KEYMSGS
vKey As Long
sKey As Long
flag As Long
time As Long
End Type
Public Const WH_KEYBOARD_LL = 13
Public Const VK_LWIN = &H5B
Public Const VK_RWIN = &H5C
Public Const HC_ACTION = 0
Public Const HC_SYSMODALOFF = 5
Public Const HC_SYSMODALON = 4
Public Const WM_KEYDOWN = &H100
Public Const WM_KEYUP = &H101
Public Const WM_SYSKEYDOWN = &H104
Public Const WM_SYSKEYUP = &H105
Public P As KEYMSGS
Public lHook As Long
Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim fEatKeystroke 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)
Select Case P.vKey
Case vbKeyF4
If (GetKeyState(vbKeyMenu) And &H8000) <> 0 Then '如果按了Alt+F4键
fEatKeystroke = True '就吃了
End If
End Select
End If
End If
If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
2、在Form中程序调用如下:
Private Sub Form_Load()
lHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)'设置键盘勾子
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnhookWindowsHookEx lHook''取消键盘勾子
End Sub
稍微进一步修改,你可以的吧……
屏蔽F4 和 WIN 就可以了
参考资料: http://hi.baidu.com/peaset
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询