29 | 03 | 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
  Else
    ISCapslockOn = False
  End If
End Function
[/code]
To test the function enter:
[code]
Sub TestFunction()
'This sub is used to test the Function Above
  If ISCapslockOn = True Then
    MsgBox "Capslock is On"
  Else
    MsgBox "Capslock is Off"
  End If
End Sub

Login

Sign up now and upload your code to the website.

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