I have a problem with key combinations. I would simulate all keyboard funciton but i can't distinguish between one modifier+key and 2 modifiers+key.
For example if i press shift+ key it work but if i press shift+altGR+ key it doesn't works becouse my program detect only altGR even if i checked if shift is pressed.
if(Keyboard.IsKeyDown(Key.RightAlt))
{
if(Keyboard.IsKeyDown(Key.LeftShift) || Keyboard.IsKeyDown(Key.RightShift))
{
Key key = e.Key;
MessageBox.Show("Shift+AlgGr+key");
}
else
{
Key key = e.Key;
MessageBox.Show("AlgGr+key");
}
}
How can i solve it? Thank you for every idea.
This should be what you need.
You can check for specific keys by using:
In your example, you are using a variable "e" which seemingly points toward EventArgs. If that is the case, e might provide the modifierCollection. (I didn´t check since I don´t know which event you are using). If it does, you should use that one instead of "Keyboard.PrimaryDevice.Modifiers".
After trying some things out, I noticed that it did not work on my computer as well if I use it in the KeyDown Eventhandler and there the e.KeyboardDevice Property. The reason for this is, that the eventHandler takes your keyboard layout into consideration. Since a non US Layout has no Right Alt (Alt GR is registered as "ALT + LEFT CTRL" by windows) this will never work. I tried changing my Layout to English-US and it worked perfectly.
So in short: To check for ALT-GR you will have to check against "ALT Modifier + CTRL Modifier".
However, there is no difference between "CTRL + ALT + SHIFT" and "ALT-GR + SHIFT" because there really isn´t one. The operating system reports ALT-GR as ALT + CTRL. The only way I see to work around this, would be by using the US Layout in your program. That however would probably result in a couple other problems, depending on what you are doing.