How do I test for Ctrl down in Windows Forms/C#?
The keydown and keyup events provide a code indicating which key is pressed, while keypress indicates which character was entered. For example, a lowercase "a" will be reported as 65 by keydown and keyup , but as 97 by keypress .
KeyDown Event : This event raised as soon as the user presses a key on the keyboard, it repeats while the user keeps the key depressed. KeyUp Event : This event is raised after the user releases a key on the keyboard.
C# This page was last reviewed on Sep 25, 2022. KeyCode handles key presses. You have a TextBox control on your Windows Forms application and need to detect Enter. With KeyCode, we can detect keys.
bool ctrl = ((Control.ModifierKeys & Keys.Control) == Keys.Control);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With