-->

Detect all the Key Pressed in keyboard

2020-03-31 07:15发布

问题:

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

回答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"); 
            }
       }


回答2:

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
    }
}


标签: c# wpf keydown