WebView2Feedback icon indicating copy to clipboard operation
WebView2Feedback copied to clipboard

Detect Shift key in Ctrl-Shift-O in KeyDown event

Open WildlifeSOS opened this issue 3 years ago • 6 comments

I am trying to circumvent the problem that the WebView2 control doesn’t behave like the WebBrowser control for hot keys/keyboard short cuts/key forwarding that is described in

https://github.com/MicrosoftEdge/WebView2Feedback/issues/468

I’m using the WebView2 keydown event and I can detect Ctrl and Alt but I can’t detect Shift in sequences like Ctrl-Shift-O (I can detect the Ctrl and the O)

As far as I can tell none of the KeyEventArgs (Modifiers, KeyData or Shift) are set to indicate that Shift has been pressed.

Is there currently anyway of detecting Shift?

AB#38461646

WildlifeSOS avatar Mar 07 '22 18:03 WildlifeSOS

Hey @JimWard2018 - Shift should be coming in as a KeyDown, similar to Ctrl. You are correct that it doesn't currently populate the KeyEventArgs as expected. We are beginning work that will improve this experience and better integrate with the .NET frameworks. Thanks!

champnic avatar Mar 07 '22 18:03 champnic

@champnic It currently isn't coming in like Ctrl; when do you expect this work to be completed so that it is?

WildlifeSOS avatar Mar 08 '22 09:03 WildlifeSOS

Aha you are right - I'm going to reopen this. The main work will be over the next few months.

In the meantime, the instructions here seem to work for me (using VK_SHIFT=0x10;): https://stackoverflow.com/questions/3829725/winforms-retrieve-keyboard-state-without-form-usercontrol

champnic avatar Mar 08 '22 17:03 champnic

That worked perfectly. Thank you @champnic

WildlifeSOS avatar Mar 09 '22 16:03 WildlifeSOS

Glad you got it working! I've opened this as a bug on our backlog to track making sure we fix this in the future.

champnic avatar Mar 09 '22 18:03 champnic

@champnic I'm seeing they KeyUp doesn't fire when the ShiftKey is released, but fires for Alt and Control. Is this related to this issue, or should I open a new one? It's causing issues with some custom hotkey handling I'm doing

Seems like the msWebView2BrowserHitTransparent feature flag helps here but it also makes Tab stop working. It doesn't move focus. Maybe I need to do some preprocessing and let it through? Not sure

Also, seems like Enter also doesn't trigger KeyUp

pushkin- avatar Aug 24 '24 15:08 pushkin-