PreviewKeyDown is not seeing Alt-modifiers

后端 未结 2 1893
名媛妹妹
名媛妹妹 2021-01-03 18:33

I have some code which is (supposed to be) capturing keystrokes. The top level window has a

Keyboard.PreviewKeyDown=\"Window_PreviewKeyDown\"
2条回答
  •  自闭症患者
    2021-01-03 19:26

    In case of an Alt modifier, e.Key returns Key.System and the real key is in e.SystemKey. You can use the following piece of code to always get the correct pressed key:

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

提交回复
热议问题