VB怎样实现锁定键盘上的一些键?

лл~~... лл~~ 展开
 我来答
匿名用户
2013-08-15
展开全部
如何在VB中实现大亏陆写锁销慎顷定,小键盘开关,Scroll Lock的指示
'//VB6.0
'//添加3个按钮:CommandScroll、CommandCapsLock、CommandNumLock
'//以及一个TIMER:Timer1
'//添加如下孝族代码:
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Sub keybd_event Lib "user32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)
Private Declare Function MapVirtualKey Lib "user32" Alias "MapVirtualKeyA" (ByVal wCode As Long, ByVal wMapType As Long) As Long
Private Const KEYEVENTF_EXTENDEDKEY = &H1
Private Const KEYEVENTF_KEYUP = &H2
Private Sub SetKeyState(ByVal Key As Long, ByVal State As Boolean)
Call keybd_event(Key, MapVirtualKey(Key, 0), KEYEVENTF_EXTENDEDKEY Or 0, 0)
Call keybd_event(Key, MapVirtualKey(Key, 0), KEYEVENTF_EXTENDEDKEY Or KEYEVENTF_KEYUP, 0)
End Sub
Private Property Get CapsLock() As Boolean
CapsLock = GetKeyState(KeyCodeConstants.vbKeyCapital) = 1
End Property
Private Property Let CapsLock(ByVal Value As Boolean)
Call SetKeyState(KeyCodeConstants.vbKeyCapital, Value)
End Property
Private Property Get NumLock() As Boolean
NumLock = GetKeyState(KeyCodeConstants.vbKeyNumlock) = 1
End Property
Private Property Let NumLock(ByVal Value As Boolean)
Call SetKeyState(KeyCodeConstants.vbKeyNumlock, Value)
End Property
Private Property Get ScrollLock() As Boolean
ScrollLock = GetKeyState(KeyCodeConstants.vbKeyScrollLock) = 1
End Property
Private Property Let ScrollLock(ByVal Value As Boolean)
Call SetKeyState(KeyCodeConstants.vbKeyScrollLock, Value)
End Property
Private Sub CommandCapsLock_Click()
CapsLock = Not CapsLock
End Sub
Private Sub CommandNumLock_Click()
NumLock = Not NumLock
End Sub
Private Sub CommandScroll_Click()
ScrollLock = Not ScrollLock
End Sub
Private Sub Timer1_Timer()
CommandCapsLock.Font.Bold = CapsLock
CommandNumLock.Font.Bold = NumLock
CommandScroll.Font.Bold = ScrollLock
End Sub
匿名用户
2013-08-15
展开全部
hHook = SetWindowsHookEx(WH_KEYBOARD, AddressOf _
MyKBHFunc, App.hInstance, App.ThreadID)

Public Function MyKBHFunc(ByVal iCode As Long, _
ByVal wParam As Long, ByVal lParam As Long) As Long
MyKBHFunc = 1 '表示要处信运森理这个讯息,作用就是吃掉所有的按键
End Function
但是不滑亩能锁悄型alt+tab
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式