永发信息网

VB怎么屏蔽WIN键?

答案:1  悬赏:0  手机版
解决时间 2021-05-10 04:31
  • 提问者网友:难遇难求
  • 2021-05-09 12:15
我在写挂机锁,如果能把其他热键也屏蔽就最好了!
最佳答案
  • 五星知识达人网友:过活
  • 2021-05-09 13:26
'***************************

'把以下程序粘贴到模块中

'***************************

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 PKBDLLHOOKSTRUCT

vkCode As Long

scanCode As Long

flags As Long

time As Long

dwExtraInfo As Long

End Type

Private Const WM_KEYDOWN = &H100

Private Const WM_SYSKEYDOWN = &H104

Private Const WM_KEYUP = &H101

Private Const WM_SYSKEYUP = &H105

Private Const VK_LWIN = &H5B

Private Const VK_RWIN = &H5C

Private Const HC_ACTION = 0

Private 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
我要举报
如以上回答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
点此我要举报以上问答信息
大家都在看
推荐资讯