How to: Determine If CapsLock is On in Visual Basic

The My.Computer.Keyboard object can be used to determine the current state of the keyboard, including such things as whether NUM LOCK or CAPS LOCK is on.

To determine if CAPS LOCK is on

  • To determine whether or not CAPS LOCK is on, use the My.Computer.Keyboard.CapsLock property. The following code displays a message about the state of the CAPS LOCK.

    If My.Computer.Keyboard.CapsLock Then
        MsgBox("CAPS LOCK is on")
    Else
        MsgBox("CAPS LOCK is off")
    End If
    

See Also

Concepts

Accessing the Keyboard

Reference

My.Computer.Keyboard Object