Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
KeyPress Event not fire on CapsLock
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
00981293
Message ID:
00981319
Views:
34
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform