Alex Rivera | Logout

How do I get the current state of Caps Lock in VB.NET?

Asked 2008-09-12T13:37:16.347
11

How do I find out whether or not Caps Lock is activated, using VB.NET?

This is a follow-up to my earlier question.

Edit
Report

1 Answer

17

Control.IsKeyLocked(Keys) Method - MSDN

Imports System
Imports System.Windows.Forms
Imports Microsoft.VisualBasic

Public Class CapsLockIndicator

    Public Shared Sub Main()
        if Control.IsKeyLocked(Keys.CapsLock) Then
            MessageBox.Show("The Caps Lock key is ON.")
        Else
            MessageBox.Show("The Caps Lock key is OFF.")
        End If
    End Sub 'Main
End Class 'CapsLockIndicator

C# version:

using System;
using System.Windows.Forms;

public class CapsLockIndicator
{
    public static void Main()
    {
        if (Control.IsKeyLocked(Keys.CapsLock)) {
            MessageBox.Show("The Caps Lock key is ON.");
        }
        else {
            MessageBox.Show("The Caps Lock key is OFF.");
        }
    }
}
answered 2008-09-12T13:41:04.043

Your Answer