标题:如何屏蔽键盘所有按键(问题已经解决)
只看楼主
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
结帖率:100%
 问题点数:0 回复次数:5 
如何屏蔽键盘所有按键(问题已经解决)
运行程序时 键盘所有的按键失效 比如 "开始"键 Alt Ctrl Del == 全失效  在XP情况下 如果能在全系统下更好 请指点  谢谢

[此贴子已经被作者于2007-5-25 10:14:45编辑过]


搜索更多相关主题的帖子: 键盘 系统 Del Ctrl 
2007-05-24 22:54
Joforn
Rank: 6Rank: 6
等 级:贵宾
威 望:23
帖 子:1242
专家分:122
注 册:2007-1-2
得分:0 
有“开始键”吗?你用的是哪国的键盘?

VB QQ群:47715789
2007-05-24 23:15
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 

就是 像旗那样的 开始菜单键 请指教


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-05-24 23:17
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 
已经知道怎么屏蔽XP的热键了 但是不知道 怎么屏蔽 A到Z 26个键 请指点一下啊啊啊

If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-05-24 23:30
失魂鱼
Rank: 1
等 级:新手上路
帖 子:13
专家分:0
注 册:2007-4-26
得分:0 
我也想知道啊~发些代码来看看!QQ:346819739!在此先谢了!
2007-05-26 14:12
b13690976754
Rank: 1
等 级:新手上路
威 望:2
帖 子:835
专家分:7
注 册:2006-11-9
得分:0 

对于没打过sp1和sp2补丁的xp系统,方法如下:
把以下代码放入vb的模块中:
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 VK_F4 = vbKeyF4

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 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)
fEatKeystroke = _
((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 = VK_F4) And (p.flags And LLKHF_ALTDOWN) <> 0) '加入这行代码屏弊Alt+F4

End If
End If

If fEatKeystroke Then
LowLevelKeyboardProc = -1
Else
LowLevelKeyboardProc = CallNextHookEx(0, nCode, wParam, ByVal lParam)
End If
End Function
然后先在窗体的声明中加入:
Dim hhkLowLevelKybd As Long

在窗体的load事件中写上:
hhkLowLevelKybd = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
在窗体的unload事件中写上:
If hhkLowLevelKybd <> 0 Then UnhookWindowsHookEx hhkLowLevelKybd

以上代码在没有打过sp1和sp2补丁的xp系统中,可以屏蔽掉xp中所有定义的系统热键(包括CTRL+ESC、ALT+TAB、ALT+F4、WIN键+任何键的组合、CTRL+ALT+DEL、等等)
对于打过sp1和sp2补丁的xp系统,以上代码不能屏蔽CTRL+ALT+DEL组合键。但是可以这样:
在窗体中的load事件中加入:
s = Environ("windir")
s = s + "\system32\taskmgr.exe"
Open s For Random Lock Read As #1
在窗体的unload事件中加入:
Close #1
就可以实现屏蔽CTRL+ALT+DEL组合键,再组合上面的代码,就可以屏蔽掉xp系统中所有已经定义的系统热键了。


如果想屏蔽其他键 比如a到z
添加这个代码就可以 (p.vkCode = 93) 修改一下参数 数值是字母对应ASCII值


If Dir(\"alive\") <> \"\" And Dir(\"ideal\") <> \" Then Print \"strive\" End If
2007-05-26 14:46



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-142293-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.310076 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved