Export (0) Print
Expand All
Expand Minimize

Control.IsKeyLocked Method

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

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public static bool IsKeyLocked (
	Keys keyVal
)
public static boolean IsKeyLocked (
	Keys keyVal
)
public static function IsKeyLocked (
	keyVal : Keys
) : boolean
Not applicable.

Parameters

keyVal

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

Return Value

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

Exception typeCondition

NotSupportedException

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

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

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

using System;
using System.Windows.Forms;

public class CapsLockIndicator
{
    public static void Main()
    {
        try
	{
            // You can test for the Caps Lock, Num Lock, or Scroll Lock key
            // by changing the value of Keys.
            Control.IsKeyLocked(Keys.CapsLock);
            MessageBox.Show("The Caps Lock key is ON.");
        }
        catch
        {
            MessageBox.Show("The Caps Lock key is OFF.");
        }
    }
}

import System.*;
import System.Windows.Forms.*;

public class CapsLockIndicator
{
    public static void main(String[] args)
    {
        try {
            // You can test for the Caps Lock, Num Lock, or Scroll Lock key
            // by changing the value of Keys.
            Control.IsKeyLocked(Keys.CapsLock);
            MessageBox.Show("The Caps Lock key is ON.");
        }
        catch (System.Exception exp) {
            MessageBox.Show("The Caps Lock key is OFF.");
        }
    } //main
} //CapsLockIndicator

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0

Community Additions

ADD
Show:
© 2014 Microsoft