Control.IsKeyLocked(Keys) Method

Definition

Determines whether the CAPS LOCK, NUM LOCK, or SCROLL LOCK key is in effect.

C#
public static bool IsKeyLocked(System.Windows.Forms.Keys keyVal);

Parameters

keyVal
Keys

The CAPS LOCK, NUM LOCK, or SCROLL LOCK member of the Keys enumeration.

Returns

true if the specified key or keys are in effect; otherwise, false.

Exceptions

The keyVal parameter refers to a key other than the CAPS LOCK, NUM LOCK, or SCROLL LOCK key.

Examples

The following code example displays a message box indicating whether the specified key (the Caps Lock key in this case) is in effect.

C#
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.");
        }
    }
}

Remarks

Use the IsKeyLocked property to determine whether the CAPS LOCK, NUM LOCK, or SCROLL LOCK keys are on, whether individually or in combination.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9