如何使用VB代码使键盘上除F1-F12外的按键全部失灵
只要求当按下F1时屏蔽其他按键,,,,,,,,,,不要求屏蔽组合键,,,谢谢了各路大神了急用...
只要求当按下F1时屏蔽其他按键,,,,,,,,,,不要求屏蔽组合键,,,谢谢了各路大神了 急用
展开
展开全部
键盘钩子。
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 Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDest As Any, pSource As Any, ByVal cb As Long)
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Type KBHOOKSTRUCT '键盘钩子的结构体
vkCode As Long '虚拟键码 shift、ctrl、alt等
scanCode As Long '扫描码
flags As Long '功能键状态
time As Long
dwExtraInfo As Long
End Type
Public Const WH_KEYBOARD_LL = 13&
Public lhook As Long '键盘钩子函数句柄
Private Const HC_ACTION = 0
Private Const LLKHF_EXTENDED = &H1
Private Const LLKHF_INJECTED = &H10
Private Const LLKHF_ALTDOWN = &H20
Private Const LLKHF_UP = &H80
Public Const VK_A = &H41
Public Const VK_ENTER = &HD
Public Const VK_TAB = &H9
Public Const VK_CONTROL = &H11
Public Const VK_ESCAPE = &H1B
Public Const VK_DELETE = &H2E
Public Const WM_KEYDOWN = &H100
'拦截的过程
Public Function KeyboardCallback(ByVal Code As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
'Code 表示拦截层次,之前我们已经说过,如果Code为0,则拦截所有窗口的键盘输入
'wParam 表示是何种Windows消息
'lParam表示某条Windows消息的具体内容的指针,它实际指向存储那个内容的内存地址
Dim Hookstruct As KBHOOKSTRUCT '定义一个局部静态结构体实例
If (Code = HC_ACTION) Then '鉴别Windows的消息来源
If wParam = WM_KEYDOWN Then
Call CopyMemory(Hookstruct, ByVal lParam, Len(Hookstruct))
'GetAsyncKeyState(VK_CONTROL) And
If Hookstruct.vkCode = vbKeyF11 Then
KeyboardCallback = 1
Exit Function
End If
End If
End If
KeyboardCallback = CallNextHookEx(lhook, Code, wParam, lParam)
End Function
form_load 挂钩
lhook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf KeyboardCallback, App.hInstance, 0)
form_unload 卸载
UnhookWindowsHookEx lhook
追问
写出来一堆红,,无法执行T T 算了还是采纳吧
展开全部
如何在VB中模拟鼠标键和键盘按键(全部键码)'函数申明
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2 '释放按键常数
'回车键例子
Private Sub Command1_Click()
Text1.SetFocus
Call keybd_event(13, 0, 0, 0) '按下
Call keybd_event(13, 0, KEYEVENTF_KEYUP, 0) '释放
End Sub
键码
常数 值 描述
vbKeyLButton 1 鼠标左键
vbKeyRButton 2 鼠标右键
vbKeyCancel 3 CANCEL 键
vbKeyMButton 4 鼠标中键
vbKeyBack 8 BACKSPACE 键
vbKeyTab 9 TAB 键
vbKeyClear 12 CLEAR 键
vbKeyReturn 13 ENTER 键
vbKeyShift 16 SHIFT 键
vbKeyControl 17 CTRL 键
vbKeyMenu 18 ALT键
vbKeyPause 19 PAUSE 键
vbKeyCapital 20 CAPS LOCK 键
vbKeyEscape 27 ESC 键
vbKeySpace 32 SPACEBAR 键
vbKeyPageUp 33 PAGEUP 键
vbKeyPageDown 34 PAGEDOWN 键
vbKeyEnd 35 END 键
vbKeyHome 36 HOME 键
vbKeyLeft 37 LEFT ARROW 键
vbKeyUp 38 UP ARROW 键
vbKeyRight 39 RIGHT ARROW 键
vbKeyDown 40 DOWN ARROW 键
vbKeySelect 41 SELECT 键
vbKeyPrint 42 PRINT SCREEN 键
vbKeyExecute 43 EXECUTE 键
vbKeySnapshot 44 SNAP SHOT 键
vbKeyInser 45 INS 键
vbKeyDelete 46 DEL 键
vbKeyHelp 47 HELP 键
vbKeyNumlock 144 NUM LOCK 键
vbKeyA 65 A 键
vbKeyB 66 B 键
vbKeyC 67 C 键
vbKeyD 68 D 键
vbKeyE 69 E 键
vbKeyF 70 F 键
vbKeyG 71 G 键
vbKeyH 72 H 键
vbKeyI 73 I 键
vbKeyJ 74 J 键
vbKeyK 75 K 键
vbKeyL 76 L 键
vbKeyM 77 M 键
vbKeyN 78 N 键
vbKeyO 79 O 键
vbKeyP 80 P 键
vbKeyQ 81 Q 键
vbKeyR 82 R 键
vbKeyS 83 S 键
vbKeyT 84 T 键
vbKeyU 85 U 键
vbKeyV 86 V 键
vbKeyW 87 W 键
vbKeyX 88 X 键
vbKeyY 89 Y 键
vbKeyZ 90 Z 键
vbKey0 48 0 键
vbKey1 49 1 键
vbKey2 50 2 键
vbKey3 51 3 键
vbKey4 52 4 键
vbKey5 53 5 键
vbKey6 54 6 键
vbKey7 55 7 键
vbKey8 56 8 键
vbKey9 57 9 键
vbKeyF1 112 F1 键
vbKeyF2 113 F2 键
vbKeyF3 114 F3 键
vbKeyF4 115 F4 键
vbKeyF5 116 F5 键
vbKeyF6 117 F6 键
vbKeyF7 118 F7 键
vbKeyF8 119 F8 键
vbKeyF9 120 F9 键
vbKeyF10 121 F10 键
vbKeyF11 122 F11 键
vbKeyF12 123 F12 键
vbKeyF13 124 F13 键
vbKeyF14 125 F14 键
vbKeyF15 126 F15 键
vbKeyF16 127 F16 键
vbkeynumpad0 96 0 键
vbkeynumpad1 97 1 键
vbkeynumpad2 98 2 键
vbkeynumpad3 99 3 键
vbkeynumpad4 100 4 键
vbkeynumpad5 101 5 键
vbkeynumpad6 102 6 键
vbkeynumpad7 103 7 键
vbkeynumpad8 104 8 键
vbkeynumpad9 105 9 键
vbkeymultiply 106 乘号 (*) 键
vbkeyadd 107 加号 (+) 键
vbkeyseparator 108 enter 键(在数字小键盘上)
vbkeysubtract 109 减号 (-) 键
vbkeydecimal 110 小数点 (.) 键
vbkeydivide 111 除号 (/) 键
38 || 上 ||
40 || 下 ||
37 || 左 ||
39 || 右 ||
'大键盘周区
9 || 大键盘左,TAB
20 || 大键盘左,大写锁定
160 || 大键盘左Shift
162 || 大键盘左,Ctrl
91 || 大键盘左,Win
13 || 大键盘右,回车
161 || 大键盘右,Shift
92 || 大键盘右,Win
93 || 大键盘右,弹菜单键
163 || 大键盘右,Ctrl
不懂得可以问,请选为满意回答
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal Scan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Const KEYEVENTF_KEYUP = &H2 '释放按键常数
'回车键例子
Private Sub Command1_Click()
Text1.SetFocus
Call keybd_event(13, 0, 0, 0) '按下
Call keybd_event(13, 0, KEYEVENTF_KEYUP, 0) '释放
End Sub
键码
常数 值 描述
vbKeyLButton 1 鼠标左键
vbKeyRButton 2 鼠标右键
vbKeyCancel 3 CANCEL 键
vbKeyMButton 4 鼠标中键
vbKeyBack 8 BACKSPACE 键
vbKeyTab 9 TAB 键
vbKeyClear 12 CLEAR 键
vbKeyReturn 13 ENTER 键
vbKeyShift 16 SHIFT 键
vbKeyControl 17 CTRL 键
vbKeyMenu 18 ALT键
vbKeyPause 19 PAUSE 键
vbKeyCapital 20 CAPS LOCK 键
vbKeyEscape 27 ESC 键
vbKeySpace 32 SPACEBAR 键
vbKeyPageUp 33 PAGEUP 键
vbKeyPageDown 34 PAGEDOWN 键
vbKeyEnd 35 END 键
vbKeyHome 36 HOME 键
vbKeyLeft 37 LEFT ARROW 键
vbKeyUp 38 UP ARROW 键
vbKeyRight 39 RIGHT ARROW 键
vbKeyDown 40 DOWN ARROW 键
vbKeySelect 41 SELECT 键
vbKeyPrint 42 PRINT SCREEN 键
vbKeyExecute 43 EXECUTE 键
vbKeySnapshot 44 SNAP SHOT 键
vbKeyInser 45 INS 键
vbKeyDelete 46 DEL 键
vbKeyHelp 47 HELP 键
vbKeyNumlock 144 NUM LOCK 键
vbKeyA 65 A 键
vbKeyB 66 B 键
vbKeyC 67 C 键
vbKeyD 68 D 键
vbKeyE 69 E 键
vbKeyF 70 F 键
vbKeyG 71 G 键
vbKeyH 72 H 键
vbKeyI 73 I 键
vbKeyJ 74 J 键
vbKeyK 75 K 键
vbKeyL 76 L 键
vbKeyM 77 M 键
vbKeyN 78 N 键
vbKeyO 79 O 键
vbKeyP 80 P 键
vbKeyQ 81 Q 键
vbKeyR 82 R 键
vbKeyS 83 S 键
vbKeyT 84 T 键
vbKeyU 85 U 键
vbKeyV 86 V 键
vbKeyW 87 W 键
vbKeyX 88 X 键
vbKeyY 89 Y 键
vbKeyZ 90 Z 键
vbKey0 48 0 键
vbKey1 49 1 键
vbKey2 50 2 键
vbKey3 51 3 键
vbKey4 52 4 键
vbKey5 53 5 键
vbKey6 54 6 键
vbKey7 55 7 键
vbKey8 56 8 键
vbKey9 57 9 键
vbKeyF1 112 F1 键
vbKeyF2 113 F2 键
vbKeyF3 114 F3 键
vbKeyF4 115 F4 键
vbKeyF5 116 F5 键
vbKeyF6 117 F6 键
vbKeyF7 118 F7 键
vbKeyF8 119 F8 键
vbKeyF9 120 F9 键
vbKeyF10 121 F10 键
vbKeyF11 122 F11 键
vbKeyF12 123 F12 键
vbKeyF13 124 F13 键
vbKeyF14 125 F14 键
vbKeyF15 126 F15 键
vbKeyF16 127 F16 键
vbkeynumpad0 96 0 键
vbkeynumpad1 97 1 键
vbkeynumpad2 98 2 键
vbkeynumpad3 99 3 键
vbkeynumpad4 100 4 键
vbkeynumpad5 101 5 键
vbkeynumpad6 102 6 键
vbkeynumpad7 103 7 键
vbkeynumpad8 104 8 键
vbkeynumpad9 105 9 键
vbkeymultiply 106 乘号 (*) 键
vbkeyadd 107 加号 (+) 键
vbkeyseparator 108 enter 键(在数字小键盘上)
vbkeysubtract 109 减号 (-) 键
vbkeydecimal 110 小数点 (.) 键
vbkeydivide 111 除号 (/) 键
38 || 上 ||
40 || 下 ||
37 || 左 ||
39 || 右 ||
'大键盘周区
9 || 大键盘左,TAB
20 || 大键盘左,大写锁定
160 || 大键盘左Shift
162 || 大键盘左,Ctrl
91 || 大键盘左,Win
13 || 大键盘右,回车
161 || 大键盘右,Shift
92 || 大键盘右,Win
93 || 大键盘右,弹菜单键
163 || 大键盘右,Ctrl
不懂得可以问,请选为满意回答
追问
这不是我想要的啊0.0
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询