I have some code which is (supposed to be) capturing keystrokes. The top level window has a
Keyboard.PreviewKeyDown="Window_PreviewKeyDown"
clause and the backing CS file contains:
private void Window_PreviewKeyDown(object sender, KeyEventArgs e) {
if (e.KeyboardDevice.Modifiers == ModifierKeys.Control) {
switch (e.Key) {
case Key.L:
btnPrev_Click(sender, new RoutedEventArgs());
e.Handled = true;
break;
case Key.R:
btnNext_Click(sender, new RoutedEventArgs());
e.Handled = true;
break;
}
}
}
Now that works fine, both CTRLL and CTRLR call the relevant functions.
As soon as I change the modifer check to use ModifierKeys.Alt
, it stops working. In other words, neither ALTL and ALTR call the functions.
What am I missing here?