ispiro ispiro - 1 year ago 161
C# Question

Get Keyboard state in Universal Windows Apps

I want to detect a key combination (e.g.

) in a Windows App. The
event handler has information about the last key pressed. But how do I find out whether the Control key is pressed as well?

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download