(WinRT) How to detect if a key modifier is pressed ?

October 13th, 2015 | Posted by Tom in .NET | Article | WinRT | Read: 3,790

For an application I’m working on, I needed to be able to detect if some modifiers (Control key, Alt key, Shift key, etc.) are pressed. In fact, it’s pretty simple to do, thanks to the GetKeyState method:

var shiftState = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Shift);
var controlState = CoreWindow.GetForCurrentThread().GetKeyState(VirtualKey.Control);

if ((shiftState & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down && (controlState & CoreVirtualKeyStates.Down) == CoreVirtualKeyStates.Down)
{
    //
}

And now, you’ll be able to now if user has pressed the shift key AND the control key Winking smile

 

Happy coding!

You can follow any responses to this entry through the RSS 2.0 You can leave a response, or trackback.

Add Comment Register



Leave a Reply