Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Silverlight handling multiple key press combinations

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?

like image 620
SilverDark Avatar asked Apr 12 '10 03:04

SilverDark


2 Answers

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
}
like image 165
DaveB Avatar answered Nov 18 '22 15:11

DaveB


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.

like image 37
Rob Smyth Avatar answered Nov 18 '22 14:11

Rob Smyth