I have a Silverlight application in which I catch certain key presses such as Tab or Ctrl to perform some action. However, I want to be able to handle multiple keys pressed at the same time such as Ctrl + R or something like that. Is there any way to do that in Silverlight, and if so, how?
Take a look at the ModifierKeys Enumeration to check for multiple key press combinations. See Silverlight Keyboard Support for code samples and more information.
void Canvas_KeyUp(object sender, KeyEventArgs e)
{
//check for the specific 'v' key, then check modifiers
if (e.Key==Key.V) {
if ((Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control) {
//specific Ctrl+V action here
}
} // else ignore the keystroke
}
Handling key combinations like Cntrl+X is very problematic with Silverlight as your running in a browser which will, probably, use most Cntrl combinations itself. Then given that you probably need to support multiple browsers such as IE, Firefox, etc I recommend you give up.
Hence I limit Silverlight key combinations to shift only.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With