Difference between KeyEventArgs.systemKey and KeyEventArgs.Key

What is the difference between KeyEventArgs.systemKey and KeyEventArgs.Key ? It is normal to catch a keypress event in a WPF Usercontrol, as shown below.

  protected override void OnKeyDown(KeyEventArgs e) { base.OnKeyDown(e); if(e.SystemKey == Key.LeftAlt || e.SystemKey == Key.LeftCtrl || e.SystemKey == Key.RightAlt) { this.Focus(); CloseAnyOpenPopups(); } } 

thanks

+7
source share
1 answer

Since the Alt key will be processed by the system using e.SystemKey , this is the only way to find out if the Alt key is pressed. The Key property will simply return Key.System .

To make sure you always get the right key, you can use this expression:

 Key key = (e.Key == Key.System ? e.SystemKey : e.Key); 
+6
source

All Articles