How to Override the default behaviour of keyboard keys in Silverlight

188 views Asked by At

I am using Silverlight 4.0,in which i am trying to develop a web application.In this application i am implementing keyboard shortcuts like Ctrl+c,Ctrl+U etc..In browsers while using Ctrl+U, debugging window is opening.Is there any way to Override these default behaviours?

2

There are 2 answers

2
Vishnu Prasad V On

You can use javascript if you wish to prevent the default actions assigned.

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();
};
0
Nitheesh On

You can achieve this by adding an eventListner to the document.

       document.addEventListener('keydown', keydownevent);

       function keydownevent (event){
            if(event.ctrlKey && event.keyCode == 85){
                event.preventDefault();
                alert("You have pressed ctrl+u")
            }
        }

Now the document will always listen for the keydown event. In order to remove this event you need to remove the eventListner from the document when the socpe of your page ends as

document.removeEventListener('keydown', keydownevent);