Check whether the Ctrl key is currently pressed in Silverlight (key modifiers)

When a key press occurs, you often need to know more than just what key was pressed, particularly modifiers such as Shift and Ctrl. To test for a Keyboard.Modifier, you use bitwise logic. For example, the following code checks whether the Ctrl key is currently pressed:

if ((Keyboard.Modifiers & ModifierKeys. Control) == ModifierKeys.Control) 
    message += "You are holding the Control key."; 

Enjoyed this post? Share it!


Leave a comment

Your email address will not be published.