@@ -248,43 +248,57 @@ private void Editor_KeyDown(object sender, KeyRoutedEventArgs e)
248
248
249
249
LastKeyPress = e . Key ;
250
250
251
- if ( GetTemplateChild ( RootControl ) is CommandBar root )
251
+ if ( GetTemplateChild ( RootControl ) is CommandBar root && IsDoingShortcut ( e . Key ) )
252
252
{
253
- if ( ControlKeyDown && e . Key != VirtualKey . Control )
254
- {
255
- var key = FindBestAlternativeKey ( e . Key ) ;
253
+ var key = FindBestAlternativeKey ( e . Key ) ;
256
254
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 )
259
259
{
260
- if ( e . Handled )
260
+ Editor . Document . Undo ( ) ;
261
+ if ( string . IsNullOrWhiteSpace ( Editor . Document . Selection . Text ) )
261
262
{
262
- Editor . Document . Undo ( ) ;
263
- if ( string . IsNullOrWhiteSpace ( Editor . Document . Selection . Text ) )
264
- {
265
- Editor . Document . Redo ( ) ;
266
- }
263
+ Editor . Document . Redo ( ) ;
267
264
}
265
+ }
268
266
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 )
271
271
{
272
- if ( button != null && ! args . Handled )
273
- {
274
- button . ShortcutRequested ( ref args ) ;
275
- }
272
+ button . ShortcutRequested ( ref args ) ;
276
273
}
274
+ }
277
275
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 ;
283
280
}
284
281
}
285
282
}
286
283
}
287
284
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
+
288
302
private KeyEventHandler KeyEventHandler { get ; set ; }
289
303
290
304
/// <summary>
@@ -295,6 +309,14 @@ public bool ControlKeyDown
295
309
get { return IsKeyActive ( CoreWindow . GetForCurrentThread ( ) . GetKeyState ( VirtualKey . Control ) ) ; }
296
310
}
297
311
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
+
298
320
/// <summary>
299
321
/// Gets a value indicating whether Shift is pressed down
300
322
/// </summary>
0 commit comments