Members

Technology Zones

IBM Learning Center

Articles

Hosted By

MaximumASP

Info

Rated
Read 17,092 times

Related Categories

Get the CAPS state

A common feature of a status bar is a small panel telling you if the CAPS lock is on or off. The code below shows you how to determine this, so you can add a panel to your status bar too!

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
Private Sub cmdIsCapsOn_Click()
    If CapsLockOn = True Then
        MsgBox "Yes, Capslock is on!"
    Else
        MsgBox "No, Capslock is NOT on!"
    End If
End Sub

James first started writing tutorials on Visual Basic in 1999 whilst starting this website (then known as VB Web). Since then, the site has grown rapidly, and James has written numerous tutorials, articles and reviews on VB, PHP, ASP and C#. In October 2003, James formed the company Developer Fusion Ltd, which owns this website, and also offers various development services. In his spare time, he's a 3rd year undergraduate studying Computer Science in the UK. He's also a Visual Basic MVP.

Comments