21 | 08 | 2017

Check if Caps Lock key status

The function ISCapslockOn checks the status of the Caps Lock key. It returns a true or false status. To check the status of the Num Lock key change vbKeyCapital for vbKeyNumLock.

Public Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Function ISCapslockOn() As Boolean
    '**** Code from VisibleVisual.com ***
    'This function will check if Caps Lock is on and returns a true or false status.
    Tmp = GetKeyState(vbKeyCapital)
  If Tmp = 1 Then
    ISCapslockOn = True
    ISCapslockOn = False
  End If
End Function
To test the function enter:
Sub TestFunction()
'This sub is used to test the Function Above
  If ISCapslockOn = True Then
    MsgBox "Capslock is On"
    MsgBox "Capslock is Off"
  End If
End Sub


Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles