Partager via


Control.IsKeyLocked(Keys) Méthode

Définition

Détermine si le verrou CAPS, NUM LOCK ou SCROLL LOCK est en vigueur.

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

Paramètres

keyVal
Keys

Le membre CAPS LOCK, NUM LOCK ou SCROLL LOCK de l’énumération Keys .

Retours

true si la clé ou les clés spécifiées sont en vigueur ; sinon, false.

Exceptions

Le keyVal paramètre fait référence à une clé autre que la touche CAPS LOCK, NUM LOCK ou SCROLL LOCK.

Exemples

L’exemple de code suivant affiche une boîte de message indiquant si la clé spécifiée (la clé de verrouillage caps dans ce cas) est en vigueur.

#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.Windows.Forms

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
End Class

Remarques

Utilisez la IsKeyLocked(Keys) méthode pour déterminer si les touches CAPS LOCK, NUM LOCK ou SCROLL LOCK sont activées individuellement ou en combinaison.

S’applique à