@@ -248,43 +248,57 @@ private void Editor_KeyDown(object sender, KeyRoutedEventArgs e)
248248
249249 LastKeyPress = e . Key ;
250250
251- if ( GetTemplateChild ( RootControl ) is CommandBar root )
251+ if ( GetTemplateChild ( RootControl ) is CommandBar root && IsDoingShortcut ( e . Key ) )
252252 {
253- if ( ControlKeyDown && e . Key != VirtualKey . Control )
254- {
255- var key = FindBestAlternativeKey ( e . Key ) ;
253+ var key = FindBestAlternativeKey ( e . Key ) ;
256254
257- var matchingButtons = root . PrimaryCommands . OfType < ToolbarButton > ( ) . Where ( item => item . ShortcutKey == key ) ;
258- if ( matchingButtons . Any ( ) )
255+ var matchingButtons = root . PrimaryCommands . OfType < ToolbarButton > ( ) . Where ( item => item . ShortcutKey == key ) ;
256+ if ( matchingButtons . Any ( ) )
257+ {
258+ if ( e . Handled )
259259 {
260- if ( e . Handled )
260+ Editor . Document . Undo ( ) ;
261+ if ( string . IsNullOrWhiteSpace ( Editor . Document . Selection . Text ) )
261262 {
262- Editor . Document . Undo ( ) ;
263- if ( string . IsNullOrWhiteSpace ( Editor . Document . Selection . Text ) )
264- {
265- Editor . Document . Redo ( ) ;
266- }
263+ Editor . Document . Redo ( ) ;
267264 }
265+ }
268266
269- var args = new ShortcutKeyRequestArgs ( key , ShiftKeyDown , e ) ;
270- foreach ( var button in matchingButtons )
267+ var args = new ShortcutKeyRequestArgs ( key , ShiftKeyDown , e ) ;
268+ foreach ( var button in matchingButtons )
269+ {
270+ if ( button != null && ! args . Handled )
271271 {
272- if ( button != null && ! args . Handled )
273- {
274- button . ShortcutRequested ( ref args ) ;
275- }
272+ button . ShortcutRequested ( ref args ) ;
276273 }
274+ }
277275
278- ShortcutRequested ? . Invoke ( this , args ) ;
279- if ( args . Handled )
280- {
281- e . Handled = true ;
282- }
276+ ShortcutRequested ? . Invoke ( this , args ) ;
277+ if ( args . Handled )
278+ {
279+ e . Handled = true ;
283280 }
284281 }
285282 }
286283 }
287284
285+ private bool IsDoingShortcut ( VirtualKey pressedKey )
286+ {
287+ // Control should be down
288+ if ( ! ControlKeyDown || pressedKey == VirtualKey . Control )
289+ {
290+ return false ;
291+ }
292+
293+ // ignore when Control is used in combination with Menu (aka Alt) to avoid blocking use of AltGr key
294+ if ( MenuKeyDown )
295+ {
296+ return false ;
297+ }
298+
299+ return true ;
300+ }
301+
288302 private KeyEventHandler KeyEventHandler { get ; set ; }
289303
290304 /// <summary>
@@ -295,6 +309,14 @@ public bool ControlKeyDown
295309 get { return IsKeyActive ( CoreWindow . GetForCurrentThread ( ) . GetKeyState ( VirtualKey . Control ) ) ; }
296310 }
297311
312+ /// <summary>
313+ /// Gets a value indicating whether Menu is pressed down
314+ /// </summary>
315+ public bool MenuKeyDown
316+ {
317+ get { return IsKeyActive ( CoreWindow . GetForCurrentThread ( ) . GetKeyState ( VirtualKey . Menu ) ) ; }
318+ }
319+
298320 /// <summary>
299321 /// Gets a value indicating whether Shift is pressed down
300322 /// </summary>
0 commit comments