Detect all the Key Pressed in keyboard

2020-03-31 07:02发布

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

标签: c# wpf keydown
2条回答
Melony?
2楼-- · 2020-03-31 07:50

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
    }
}
查看更多
该账号已被封号
3楼-- · 2020-03-31 08:04

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"); 
            }
       }
查看更多
登录 后发表回答