Begin VB.Form Form1
Caption = "Key States"
ClientHeight = 825
ClientLeft = 60
ClientTop = 345
ClientWidth = 4440
LinkTopic = "Form1"
ScaleHeight = 825
ScaleWidth = 4440
StartUpPosition = 3 'Windows Default
Begin VB.Timer tmrKeyStates
Interval = 1000
Left = 0
Top = 0
End
Begin VB.TextBox Text3
Height = 375
Left = 3000
TabIndex = 2
Top = 240
Width = 1200
End
Begin VB.TextBox Text2
Height = 375
Left = 1680
TabIndex = 1
Top = 240
Width = 1200
End
Begin VB.TextBox Text1
Height = 375
Left = 240
TabIndex = 0
Top = 240
Width = 1200
End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private Declare Function GetKeyState Lib _
"user32" (ByVal nVirtKey As Long) As Integer
Public Function CapsLockOn() As Boolean
Dim iKeyState As Integer
iKeyState = GetKeyState(vbKeyCapital)
CapsLockOn = (iKeyState = 1 Or iKeyState = -127)
End Function
Public Function NumLockOn() As Boolean
Dim iKeyState As Integer
iKeyState = GetKeyState(vbKeyNumlock)
NumLockOn = (iKeyState = 1 Or iKeyState = -127)
End Function
Public Function ScrlLockOn() As Boolean
Dim iKeyState As Integer
iKeyState = GetKeyState(vbKeyScrollLock)
ScrlLockOn = (iKeyState = 1 Or iKeyState = -127)
End Function
Private Sub Form_Load()
Text1.Enabled = False
Text2.Enabled = False
Text3.Enabled = False
End Sub
Private Sub tmrKeyStates_Timer()
If NumLockOn() Then
Text1.Text = ("NUM On")
Else
Text1.Text = ("NUM Off")
End If
If CapsLockOn() Then
Text2.Text = ("CAPS On")
Else
Text2.Text = ("CAPS Off")
End If
If ScrlLockOn() Then
Text3.Text = ("SCR On")
Else
Text3.Text = ("SCR Off")
End If
End Sub