Determines whether the CAPS LOCK, NUM LOCK, or SCROLL LOCK key is in effect.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Syntax . . :: . Boolean
true if the specified key or keys are in effect; otherwise, false.
Public Shared Function IsKeyLocked ( _
keyVal As Keys _
) As Booleanpublic static bool IsKeyLocked(
Keys keyVal
)public:
static bool IsKeyLocked(
Keys keyVal
)static member IsKeyLocked :
keyVal:Keys -> bool
Parameters
- keyVal
- Type: System.Windows.Forms
. . :: . Keys
The CAPS LOCK, NUM LOCK, or SCROLL LOCK member of the Keys enumeration.
Return Value
Type: Systemtrue if the specified key or keys are in effect; otherwise, false.
Exceptions
| Exception | Condition |
|---|---|
| NotSupportedException | 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.
' 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()
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
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.");
}
}
}
#using <System.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
using namespace System;
using namespace System::Windows::Forms;
int main()
{
if (Control::IsKeyLocked( Keys::CapsLock )) {
MessageBox::Show( "The Caps Lock key is ON." );
}
else {
MessageBox::Show( "The Caps Lock key is OFF." );
}
}
Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.