vb锁定某个键盘

 我来答
风雪剑无痕
2012-07-13 · TA获得超过1253个赞
知道大有可为答主
回答量:1691
采纳率:100%
帮助的人:1677万
展开全部
'模块代码
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 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 HC_ACTION = 0
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 vbKeyA
fEatKeystroke = True
End Select
End If
End If
If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function

'窗体代码
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
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
百度网友c01acee
2012-07-14 · TA获得超过187个赞
知道小有建树答主
回答量:587
采纳率:0%
帮助的人:380万
展开全部
全局钩子
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
shuenjinmin
2012-07-15 · 超过28用户采纳过TA的回答
知道答主
回答量:198
采纳率:0%
帮助的人:94.7万
展开全部
API函数、、、、、、、、
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 更多回答(1)
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式