KeyDown : recognizing multiple keys

后端 未结 13 2761
悲&欢浪女
悲&欢浪女 2020-12-03 02:47

How can I determine in KeyDown that CtrlUp was pressed.

private void listView1_KeyDown(object sender, KeyEventArgs e)
{
           


        
13条回答
  •  感动是毒
    2020-12-03 03:07

    private void listView1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.Key == Key.Up && Keyboard.IsKeyDown(Key.LeftCtrl))
        {
             //do stuff
        }
    }
    

    This code will work only if you press first LeftCtrl, then "UP". If order has no importance, I recommend that one :

    if ((Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightCtrl))&& Keyboard.IsKeyDown(Key.Z))
    {
        //do stuff
    }
    

    In that case, both Ctrl are taken in account, and no importance about the order.

提交回复
热议问题