vb 锁定计算机,锁定键盘
一、在VB中,按下command1,相当于在键盘上按下了"windows+L"键,如何实现;二、怎样一键锁定键盘和鼠标。初学者问,请详答,谢谢...
一、在VB中,按下command1,相当于在键盘上按下了"windows+L"键,如何实现;
二、怎样一键锁定键盘和鼠标。
初学者问,请详答,谢谢 展开
二、怎样一键锁定键盘和鼠标。
初学者问,请详答,谢谢 展开
1个回答
展开全部
用keybd_event模拟键盘函数实现
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
keybd_event 91, 0, 0, 0
keybd_event 76, 0, 0, 0
End Sub
2.锁定键盘和鼠标?是不是不让他们输入?下面是鼠标和键盘的一种限制程序,你可以在基础上加深一下
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim Locked As RECT
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Sub Form_Load() '作初始化设置。
Timer1.Enabled = False
Command1.Caption = "锁定"
Command2.Caption = "释放"
Form1.Caption = "锁定鼠标的程序"
End Sub
Private Sub Command1_Click() '启动锁定鼠标程序
Timer1.Interval = 50
Timer1.Enabled = True
Locked.Left = 0: Locked.Top = 0 '鼠标范围设置为0
Locked.Right = 0: Locked.Bottom = 0
ClipCursor Locked
End Sub
'结束timer检测,释放鼠标
Private Sub Command2_Click()
Timer1.Enabled = False
ClipCursor ByVal 0
End Sub
'timer检测,锁定鼠标的活动范围
Private Sub Timer1_Timer()
ClipCursor Locked
End Sub
键盘码是别人的
'模块中
Public hHook As Long
Public h_Hook As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
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
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Long) As Long
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP As Long = &H205
Public Const WH_KEYBOARD_LL = 13
Public Function MyKBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
MyKBHook = 1
End If
End Function
Public Function My_KBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
If wParam = WM_MOUSEMOVE Then
My_KBHook = CallNextHookEx(h_Hook, ncode, wParam, lParam)
Else
My_KBHook = 1
End If
End If
End Function
'窗体中
Private Sub Form_Load()
Open Environ("windir") & "\system32" & "\taskmgr.exe" For Random Lock Read As #1
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf MyKBHook, App.hInstance, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnhookWindowsHookEx(hHook)
End Sub
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Sub Command1_Click()
keybd_event 91, 0, 0, 0
keybd_event 76, 0, 0, 0
End Sub
2.锁定键盘和鼠标?是不是不让他们输入?下面是鼠标和键盘的一种限制程序,你可以在基础上加深一下
Option Explicit
Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type
Dim Locked As RECT
Private Declare Function ClipCursor Lib "user32" (lpRect As Any) As Long
Private Sub Form_Load() '作初始化设置。
Timer1.Enabled = False
Command1.Caption = "锁定"
Command2.Caption = "释放"
Form1.Caption = "锁定鼠标的程序"
End Sub
Private Sub Command1_Click() '启动锁定鼠标程序
Timer1.Interval = 50
Timer1.Enabled = True
Locked.Left = 0: Locked.Top = 0 '鼠标范围设置为0
Locked.Right = 0: Locked.Bottom = 0
ClipCursor Locked
End Sub
'结束timer检测,释放鼠标
Private Sub Command2_Click()
Timer1.Enabled = False
ClipCursor ByVal 0
End Sub
'timer检测,锁定鼠标的活动范围
Private Sub Timer1_Timer()
ClipCursor Locked
End Sub
键盘码是别人的
'模块中
Public hHook As Long
Public h_Hook As Long
Declare Function UnhookWindowsHookEx Lib "user32" (ByVal hHook As Long) As Long
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
Declare Function CallNextHookEx Lib "user32" (ByVal hHook As Long, ByVal ncode As Long, ByVal wParam As Long, lParam As Long) As Long
Public Const WM_LBUTTONDOWN = &H201
Public Const WM_LBUTTONUP = &H202
Public Const WM_RBUTTONDOWN = &H204
Public Const WM_RBUTTONUP As Long = &H205
Public Const WH_KEYBOARD_LL = 13
Public Function MyKBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
MyKBHook = 1
End If
End Function
Public Function My_KBHook(ByVal ncode As Long, ByVal wParam As Long, ByVal lParam As Long) As Long
If ncode = 0 Then
If wParam = WM_MOUSEMOVE Then
My_KBHook = CallNextHookEx(h_Hook, ncode, wParam, lParam)
Else
My_KBHook = 1
End If
End If
End Function
'窗体中
Private Sub Form_Load()
Open Environ("windir") & "\system32" & "\taskmgr.exe" For Random Lock Read As #1
hHook = SetWindowsHookEx(WH_KEYBOARD_LL, AddressOf MyKBHook, App.hInstance, 0)
End Sub
Private Sub Form_Unload(Cancel As Integer)
Call UnhookWindowsHookEx(hHook)
End Sub
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询