开发者

Detect Shift+1 as Key.Add

开发者 https://www.devze.com 2023-02-09 21:51 出处:网络
I wou开发者_如何转开发ld like to detect the user pressing the \"add\" key in the .net 4 WPF KeyDown event handler. To do this I use the following test:

I wou开发者_如何转开发ld like to detect the user pressing the "add" key in the .net 4 WPF KeyDown event handler. To do this I use the following test:

if (e.Key == Key.Add)

This doesn't detect the case when the user presses Shift+1 (which corresponds to "add" on my keyboard layout).

How can I detect this? I'm not convinced that testing

if (e.Key == Key.D1 && Keyboard.Modifiers == ModifierKeys.Shift)

is the right solution as it may be mapped elsewhere on another keyboard layout.

Any suggestions?


You might consider using the KeyPress event handler instead.


private void trackBarFrames_KeyDown(object sender, KeyEventArgs e)
{
    switch ( e.KeyCode)
    {
        case Keys.Add :
            // Nummeric Keypad Add 
            AddSomething();
            break;
        case Keys.Oemplus :
            // Regular keyboard Add
            // OemPlus is assigned to the regular keyboard key with a "Add" Sign but doesn not take shift conditions in account..!
            if (e.Modifiers == Keys.Shift)
            {
                AddSomething();
            }
            break;
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号