KeyDown : recognizing multiple keys

后端 未结 13 2782
悲&欢浪女
悲&欢浪女 2020-12-03 02:47

How can I determine in KeyDown that CtrlUp was pressed.

private void listView1_KeyDown(object sender, KeyEventArgs e)
{
           


        
13条回答
  •  余生分开走
    2020-12-03 03:23

    It took me a while to find the hint I ultimately needed when trying to detect [Alt][Right]. I found it here: https://social.msdn.microsoft.com/Forums/vstudio/en-US/4355ab9a-9214-4fe1-87ea-b32dfc22946c/issue-with-alt-key-and-key-down-event?forum=wpf

    It boils down to something like this in a Shortcut helper class I use:

    public Shortcut(KeyEventArgs e) : this(e.Key == System.Windows.Input.Key.System ? e.SystemKey : e.Key, Keyboard.Modifiers, false) { }
    
    public Shortcut(Key key, ModifierKeys modifiers, bool createDisplayString)
    {
        ...
    } 
    

    After "re-mapping" the original values (notice the e.Key == System.Windows.Input.Key.System ? e.SystemKey : e.Key part), further processing can go on as usual.

提交回复
热议问题