Control.IsKeyLocked(Keys) Control.IsKeyLocked(Keys) Control.IsKeyLocked(Keys) Control.IsKeyLocked(Keys) Method

定义

确定 Caps Lock、Num Lock 或 Scroll Lock 键是否有效。Determines whether the CAPS LOCK, NUM LOCK, or SCROLL LOCK key is in effect.

public:
 static bool IsKeyLocked(System::Windows::Forms::Keys keyVal);
public static bool IsKeyLocked (System.Windows.Forms.Keys keyVal);
static member IsKeyLocked : System.Windows.Forms.Keys -> bool
Public Shared Function IsKeyLocked (keyVal As Keys) As Boolean

参数

keyVal
Keys Keys Keys Keys

Keys 枚举的 Caps Lock、Num Lock 或 Scroll Lock 成员。The CAPS LOCK, NUM LOCK, or SCROLL LOCK member of the Keys enumeration.

返回

如果指定的一个或多个键有效,则为 true;否则为 falsetrue if the specified key or keys are in effect; otherwise, false.

异常

keyVal参数引用非 CAPS LOCK、 NUM LOCK 或 SCROLL LOCK 键的键。The keyVal parameter refers to a key other than the CAPS LOCK, NUM LOCK, or SCROLL LOCK key.

示例

下面的代码示例显示一个消息框,该值指示指定的键 (在本例中为 Caps Lock 键) 是否有效。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.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." );
   }

}

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

' 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

注解

使用IsKeyLocked属性来确定 CAPS LOCK、 NUM LOCK 或 SCROLL LOCK 键是否,是否单独或组合。Use the IsKeyLocked property to determine whether the CAPS LOCK, NUM LOCK, or SCROLL LOCK keys are on, whether individually or in combination.

适用于