vb屏蔽键盘上部分键3
发布网友
发布时间:2023-10-30 20:07
我来回答
共3个回答
热心网友
时间:2024-03-14 00:07
分二步:
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 就可以了
热心网友
时间:2024-03-13 23:59
我可以帮你完成,但是必须先选择我最佳。
屏蔽也C+a+d也可以。
热心网友
时间:2024-03-14 00:04
peaset 十二级的果然厉害。