When mouse clicking or typing a key in your Silverlight application how do you know if any combination of the <Alt>, <Shift>, <Ctrl>, <Windows> and/or <Apple> keys are down as well?
To accomplish this you simply need to check the Keyboard.Modifiers member which returns a ModifierKeys object.
The following code demonstrates how to get this object and how to check if any of these keys have been pressed:
ModifierKeys keys = Keyboard.Modifiers;
bool shiftKey = (keys & ModifierKeys.Shift) != 0;
bool altKey = (keys & ModifierKeys.Alt) != 0;
bool appleKey = (keys & ModifierKeys.Apple) != 0;
bool controlKey = (keys & ModifierKeys.Control) != 0;
bool windowsKey = (keys & ModifierKeys.Windows) != 0;
Source: Tip8_ModifierKeys
Demo:
[silverlight: Tip8_ModiferKeys.xap]
Thank you,
–Mike







Shift- and Ctrl-keys work. Alt alone doesn’t Alt Gr and ctrl+alt works. Windows shows
Using english XP sp3 with swedish keyboard.
Love the new blog!
Very useful! Thanks.
Hi
Why would this not work for us? We do not get the ALT modifier to fire at all, only when pressed with control does it work. Alt-A for example also does not fire a KeyDownEvent.
This is true for in- and out-of-browser.