How to know when a modifier is pressed on KeyDown event? WinUI3 repview4
See original GitHub issueIn preview3 of WinUI3 I was using the following code to know whether the Shift key was pressed while listening to the KeyDown event
var cw = CoreWindow.GetForCurrentThread();
return cw.GetAsyncKeyState(VirtualKey.Shift) != CoreVirtualKeyStates.None;
This stopped working on preview4 (for Desktop)
The KeyRoutedEventArgs doesn’t come with a KeyModifiers property as the PointerRoutedEventArgs.
How should we detect shift or control pressed in KeyDown event?
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
KeyboardAccelerator.Modifiers Property - Windows
A keyboard shortcut is invoked when the modifier keys associated with the shortcut are pressed and then the non-modifier key is pressed at...
Read more >How to: Determine Which Modifier Key Was Pressed - ...
Use the bitwise AND operator with the ModifierKeys property and a value of the Keys enumeration to determine whether a particular modifier key ......
Read more >c# - Detecting modifier key down?
The eventing behavior that I'm seeing for modifier keys is different than other keys --- it looks like the KeyDown event and PreviewKeyDown ......
Read more >KeyboardEvent: getModifierState() method - Web APIs | MDN
The KeyboardEvent.getModifierState() method returns the current state of the specified modifier key: true if the modifier is active (that is ...
Read more >How to detect the key events in JavaScript
The keydown event is fired repeatedly when the key is pressed for a long time without releasing. We can detect if the event...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@sassy224 Microsoft.UI.Input.KeyboardInput.GetKeyStateForCurrentThread is now Microsoft.UI.Input.InputKeyboardSource.GetKeyStateForCurrentThread starting with Windows AppSDK 1.0.0-preview2
See other changes here, documented by .Morten: https://twitter.com/dotMorten/status/1445821064269860867
I found that using Microsoft.UI.Xaml.Input.KeyRoutedEventArgs is working, something like
keyEventArgs.Key == Key.Control;
is working for me.