2个回答
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
'//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
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询