1

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

bRaNdOn
  • 910
  • 3
  • 15
  • 31

2 Answers2

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
  • 760
  • 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
  • 203,447
  • 57
  • 330
  • 376