程序代码: | [ 复制代码 ] |
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
'/石陆软件屋转录
'/http://www.cnng.net
Private Sub SetKeyState(intKey As Integer, fTurnOn As Boolean)
'取得键盘目前的状态,设定您想设定的任意键,再将其他键还成之前的状态,只改变一个键值
Dim abytBuffer(0 To 255) As Byte
GetKeyboardState abytBuffer(0)
abytBuffer(intKey) = CByte(Abs(fTurnOn))
SetKeyboardState abytBuffer(0)
End Sub
Function GetCapslock() As Boolean
'返回 Capslock 的状态
GetCapslock = CBool(GetKeyState(vbKeyCapital) And 1)
End Function
Function GetNumlock() As Boolean
'返回 Numlock 的状态
GetNumlock = CBool(GetKeyState(vbKeyNumlock) And 1)
End Function
Function GetScrollLock() As Boolean
'返回 ScrollLock 的状态
GetScrollLock = CBool(GetKeyState(vbKeyScrollLock) And 1)
End Function
Sub SetCapslock(Value As Boolean)
'设定 Capslock 的状态
Call SetKeyState(vbKeyCapital, Value)
End Sub
Sub SetNumlock(Value As Boolean)
'设定 Numlock 的状态
Call SetKeyState(vbKeyNumlock, Value)
End Sub
Sub SetScrollLock(Value As Boolean)
'设定 ScrollLock 的状态
Call SetKeyState(vbKeyScrollLock, Value)
End Sub
Private Sub Command1_Click()
SetNumlock True ' 设定 ScrollLock 为 On
End Sub
Private Sub Command2_Click()
MsgBox "GetNumlock(WWW.cnng.net):" & GetNumlock ' 取得 ScrollLock 状态
End Sub
Private Declare Function GetKeyboardState Lib "user32" (pbKeyState As Byte) As Long
Private Declare Function SetKeyboardState Lib "user32" (lppbKeyState As Byte) As Long
'/石陆软件屋转录
'/http://www.cnng.net
Private Sub SetKeyState(intKey As Integer, fTurnOn As Boolean)
'取得键盘目前的状态,设定您想设定的任意键,再将其他键还成之前的状态,只改变一个键值
Dim abytBuffer(0 To 255) As Byte
GetKeyboardState abytBuffer(0)
abytBuffer(intKey) = CByte(Abs(fTurnOn))
SetKeyboardState abytBuffer(0)
End Sub
Function GetCapslock() As Boolean
'返回 Capslock 的状态
GetCapslock = CBool(GetKeyState(vbKeyCapital) And 1)
End Function
Function GetNumlock() As Boolean
'返回 Numlock 的状态
GetNumlock = CBool(GetKeyState(vbKeyNumlock) And 1)
End Function
Function GetScrollLock() As Boolean
'返回 ScrollLock 的状态
GetScrollLock = CBool(GetKeyState(vbKeyScrollLock) And 1)
End Function
Sub SetCapslock(Value As Boolean)
'设定 Capslock 的状态
Call SetKeyState(vbKeyCapital, Value)
End Sub
Sub SetNumlock(Value As Boolean)
'设定 Numlock 的状态
Call SetKeyState(vbKeyNumlock, Value)
End Sub
Sub SetScrollLock(Value As Boolean)
'设定 ScrollLock 的状态
Call SetKeyState(vbKeyScrollLock, Value)
End Sub
Private Sub Command1_Click()
SetNumlock True ' 设定 ScrollLock 为 On
End Sub
Private Sub Command2_Click()
MsgBox "GetNumlock(WWW.cnng.net):" & GetNumlock ' 取得 ScrollLock 状态
End Sub
引用通告地址 (0):
http://www.cnng.net/blog/trackback.asp?tbID=108
http://www.cnng.net/blog/trackback.asp?tbID=108&CP=GBK
http://www.cnng.net/blog/trackback.asp?tbID=108
http://www.cnng.net/blog/trackback.asp?tbID=108&CP=GBK