VB如何设置禁止通过热键启动任何软件?
就是启动软件之后,任何热键都禁用了。
追问:方便的话,帮我看看能不能这样,禁止Win键的同时,也禁止Alt+Ctrl+delete键?
就是启动软件之后,任何热键都禁用了。
追问:方便的话,帮我看看能不能这样,禁止Win键的同时,也禁止Alt+Ctrl+delete键?
答案:VB禁止win键(修改可以禁止任意热键)'把以下程序粘贴到模块中
'***************************
Option Explicit
Private Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal nCode As Long, ByVal wParam As Long, lParam As Any) As Long
Private 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
Private Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Any, Source As Any, ByVal Length As Long)
Private Type PKBDLLHOOKSTRUCTvkCode As Long
scanCode As Long
flags As Long
time As Long
dwExtraInfo As Long
End Type
Private Const WM_KEYDOWN = &H100Private Const WM_SYSKEYDOWN = &H104
Private Const WM_KEYUP = &H101
Private Const WM_SYSKEYUP = &H105
Private Const VK_LWIN = &H5BPrivate Const VK_RWIN = &H5C
Private Const HC_ACTION = 0Private Const WH_KEYBOARD_LL = 13
Private lngHook As Long
'使用底层KeyboardHook拦截按键消息Public Function LowLevelKeyboardProc(ByVal nCode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
Dim blnHook As Boolean
Dim p As PKBDLLHOOKSTRUCT
If nCode = HC_ACTION Then
Select Case wParam
Case WM_KEYDOWN, WM_SYSKEYDOWN, WM_KEYUP, WM_SYSKEYUP
Call CopyMemory(p, ByVal lParam, Len(p))
If p.vkCode = VK_LWIN Or p.vkCode = VK_RWIN Then '按下了左/右Win键
blnHook = True
End If
Case Else
'do nothing
End Select
End If
If blnHook Then
LowLevelKeyboardProc = 1
Else
Call CallNextHookEx(WH_KEYBOARD_LL, nCode, wParam, lParam)
End If
End Function
Public Sub HooK()lngHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf LowLevelKeyboardProc, App.hInstance, 0)
End Sub
Public Sub UnHooK()Call UnhookWindowsHookEx(lngHook)
End Sub
'***************************
'把以下程序粘贴到窗体中
'***************************
Private Sub Form_Load()
Hook
End Sub
Private Sub Form_Unload(Cancel As Integer)
UnHook
End Sub
键盘常用ASCII码 2007-04-13 16:31
ESC键 VK_ESCAPE (27) Insert键: VK_INSERT (45) 方向键(←): VK_LEFT (37)
|
这么做,不合适吧。
当然也能,可以做个屏蔽列表。
但是。。。太易做图了吧。
而且工作量蛮大,不同操作系统,也不一样,要分别写代码的。
如果是学习的角度,建议你参考MSDN,
如果是干别的,你可以用第三方控件实现,我记得有人放出来过类似的模块。
上一个:请问如何用VB程序来模拟键盘操作
下一个:关于VB的块IF嵌套问题