This documentation is archived and is not being maintained.

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)

'Declaration
Public Shared Function IsKeyLocked ( _
	keyVal As Keys _
) As Boolean
'Usage
Dim keyVal As Keys
Dim returnValue As Boolean

returnValue = Control.IsKeyLocked(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.


' To compile and run this sample from the command line, proceed as follows:
' vbc controliskeylocked.vb /r:System.Windows.Forms.dll /r:System.dll 
' /r:System.Data.dll /r:System.Drawing.dll

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

Public Class CapsLockIndicator
   
    Public Shared Sub 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.")
        End Try
    End Sub 'Main
End Class 'CapsLockIndicator

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
Show: