is there a way to detect all the key pressed in keydown event of the form? For example im currently pressing CRTL + Alt + A can i get all the keys in keydown event? i need to get all the keys to create my own hot keys in my currently developing application
Asked
Active
Viewed 1,499 times
1
-
http://stackoverflow.com/questions/1752494/detect-if-any-key-is-pressed-in-c-sharp-not-a-b-but-any – Sajeetharan Jun 11 '14 at 08:45
-
Hi i didnt get all the pressed key by applying this to my project any idea? – bRaNdOn Jun 11 '14 at 08:53
-
you want to know what keys are presseD? – Sajeetharan Jun 11 '14 at 08:54
-
Yes is there a way to do it? – bRaNdOn Jun 11 '14 at 08:59
2 Answers
1
You can check for all keys in event arguments
private void Form1_KeyDown(object sender, KeyEventArgs e)
{
if (e.Alt && e.Control && e.KeyCode == Keys.A)
{
//do something
}
}

pen2
- 759
- 5
- 16
-
The question was about all keys, to create a hotkeys combination, so chekcing every property in 'e' isn't a good idea. – prvit Jun 11 '14 at 09:00
1
If you want to find which keys are pressed, you could do this,
if ((Keyboard.Modifiers & ModifierKeys.Alt) == ModifierKeys.Alt) // Is Alt key pressed
{
if (Keyboard.IsKeyDown(Key.LeftCtrl) && Keyboard.IsKeyDown(Key.A))
{
MessageBox.Show("Key pressed");
}
}

Sajeetharan
- 216,225
- 63
- 350
- 396