Get Keyboard state in Universal Windows Apps

后端 未结 2 1951
轮回少年
轮回少年 2021-01-02 00:51

I want to detect a key combination (e.g. Control-A) in a Windows App. The KeyDown event handler has information about the last key pressed. But how

2条回答
  •  天命终不由人
    2021-01-02 01:48

    You can use CoreVirtualKeyStates.HasFlag(CoreVirtualKeyStates.Down) to determine is the Ctrl key has been pressed, like this -

    Window.Current.CoreWindow.KeyDown += (s, e) =>
    {
        var ctrl = Window.Current.CoreWindow.GetKeyState(VirtualKey.Control);
        if (ctrl.HasFlag(CoreVirtualKeyStates.Down) && e.VirtualKey == VirtualKey.A)
        {
            // do your stuff
        }
    };
    

提交回复
热议问题