Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
KeyPress Event not fire on CapsLock
Message
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Divers
Thread ID:
00981293
Message ID:
00981319
Vues:
35
This message has been marked as the solution to the initial question of the thread.
The KeyPress event is only triggered for ASCII characters (letters, digits, punctuations, ...).

To trap the CapsLock key, you have to use the KeyDown (or KeyUp) event. You will then need to replace the KeyChar property with KeyCode.


>I have the following code:
>
>private void MainForm_KeyPress(object sender, System.Windows.Forms.KeyPressEventArgs e)
>{
> if ((int)e.KeyChar == (int)Keys.CapsLock){MessageBox.Show("Caps Lock On");}
>}
>
>And the KeyPreview is set to True.
>However, when I press CapsLock key this does not fire. It does fire if press a letter key.
>Why?
>
>TIA
Éric Moreau, MCPD, Visual Developer - Visual Basic MVP
Conseiller Principal / Senior Consultant
Moer inc.
http://www.emoreau.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform