ch40s
ch40s

Reputation: 590

ModifierKeys.None not working. ctrl+add triggers "ctrl+add" and "add"

I got a little problem I just can't figure out:

I want two different keyboard shortcuts to work. The one being ctrl+add, the other being add alone. The problem is, whenever I press ctrl+add the add command is executed also.

I tried it with the following code (I used KeyDown event):

if (Keyboard.Modifiers == ModifierKeys.Control && e.Key == Key.Add)
        something();

if (Keyboard.Modifiers == ModifierKeys.None && e.Key == Key.Add)
        someOther();

Upvotes: 1

Views: 550

Answers (1)

Clemens
Clemens

Reputation: 128076

You could write this:

if (e.Key == Key.Add)
{
    if (Keyboard.Modifiers == ModifierKeys.Control)
    {  
        something();  
    }
    else if (Keyboard.Modifiers == ModifierKeys.None)
    {  
        someOther();
    }
}

Upvotes: 1

Related Questions