简体   繁体   English

Silverlight处理多个按键组合

[英]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. 我有一个Silverlight应用程序,我在其中捕获某些按键,如TabCtrl来执行某些操作。 However, I want to be able to handle multiple keys pressed at the same time such as Ctrl + R or something like that. 但是,我希望能够同时处理多个按键,例如Ctrl + R或类似的东西。 Is there any way to do that in Silverlight, and if so, how? 有没有办法在Silverlight中做到这一点,如果是这样,怎么样?

Take a look at the ModifierKeys Enumeration to check for multiple key press combinations. 查看ModifierKeys Enumeration以检查多个按键组合。 See Silverlight Keyboard Support for code samples and more information. 有关代码示例和更多信息,请参阅Silverlight键盘支持

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. 处理像Cntrl + X这样的关键组合是非常有问题的,因为你在浏览器中运行Silverlight可能会使用大多数Cntrl组合本身。 Then given that you probably need to support multiple browsers such as IE, Firefox, etc I recommend you give up. 然后考虑到你可能需要支持IE,Firefox等多种浏览器,我建议你放弃。

Hence I limit Silverlight key combinations to shift only. 因此,我将Silverlight键组合限制为仅移位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM