Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/silverlight/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何在Silverlight中覆盖键盘键的默认行为_C#_Silverlight_Silverlight 4.0_Keyboard Shortcuts - Fatal编程技术网

C# 如何在Silverlight中覆盖键盘键的默认行为

C# 如何在Silverlight中覆盖键盘键的默认行为,c#,silverlight,silverlight-4.0,keyboard-shortcuts,C#,Silverlight,Silverlight 4.0,Keyboard Shortcuts,我正在使用Silverlight 4.0,我试图在其中开发一个web应用程序。在这个应用程序中,我在浏览器中使用Ctrl+c、Ctrl+U等快捷键,同时使用Ctrl+U,调试窗口正在打开。是否有任何方法覆盖这些默认行为?如果希望阻止指定的默认操作,可以使用javascript document.body.onkeydown = function(e){ //verify the control press you want to prevent and call preventDefaul

我正在使用
Silverlight 4.0
,我试图在其中开发一个web应用程序。在这个应用程序中,我在浏览器中使用
Ctrl+c、Ctrl+U等
快捷键,同时使用
Ctrl+U
,调试窗口正在打开。是否有任何方法覆盖这些默认行为?

如果希望阻止指定的默认操作,可以使用
javascript

document.body.onkeydown = function(e){
   //verify the control press you want to prevent and call preventDefault()
   //ex : if (e.ctrlKey && e.which == 84)
   e.preventDefault();
};

您可以通过向文档中添加
eventListner
来实现这一点

       document.addEventListener('keydown', keydownevent);

       function keydownevent (event){
            if(event.ctrlKey && event.keyCode == 85){
                event.preventDefault();
                alert("You have pressed ctrl+u")
            }
        }
现在,文档将始终侦听
按键事件
。为了删除此事件,当页面的socpe结束为时,需要从文档中删除eventListner

document.removeEventListener('keydown', keydownevent);

我需要同时访问Ctrl+U键,这是通过Javascript无法访问的。@VVN实际上你可以,如果按下Ctrl键,
e.ctrlKey
将是
true