Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override the browser shortcuts by my own custom shortcuts

I created one Asp.net MVC4 web application using C# which we can dynamically create keyboard shortcuts for all the pages.And we can use that keyboard shortcuts instantly to go to specific page.And the problem is every browser have their own default shortcuts.For example

If I create the keyboard shortcut CTRL + A it should redirect to my own custom page. But the default browser shortcut CTRL + A selects all from the page instead.

I want to disable the default browser shortcuts to give priority to my own custom shortcuts.Is this any way to achieve these? For my custom shortcuts,i used jquery keyUp event.I searched on internet,there suggestion are on jquery keyUp event,use preventDefault().But for accessing my own custom shortcuts,i am using keyUp event.So tell me suggestions to disable default browser shortcuts in all browsers either by C#, jquery or any other way.

like image 447
venki Avatar asked Feb 24 '15 09:02

venki


1 Answers

This will let you do this:

e.ctrlKey && String.fromCharCode(kc).toUpperCase()

checks for Ctrl + A to be pressed.

$(document).on('keydown', function(e) {
  var kc = e.which || e.keyCode;

  if (e.ctrlKey && String.fromCharCode(kc).toUpperCase() == "A") {
    e.preventDefault();
    console.log(String.fromCharCode(kc).toUpperCase());
    window.location.href = 'your url here';
  }
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
adfasfasdfsda
You should click in the document to focus and then you can test it.
like image 142
Jai Avatar answered Oct 13 '22 01:10

Jai