Override browser shortcuts with my own shortcuts

I created one Asp.net MVC4 web application using C #, which we can dynamically create keyboard shortcuts for all pages. And we can quickly use these keyboard shortcuts to go to a specific page. And the problem is that each browser has its own default shortcuts. for instance

If I create a CTRL + A key combination, it should be redirected to my own page. But the default browser shortcut CTRL + A selects everything from the page.

I want to disable the default browser shortcuts to give priority to my own shortcuts. Is this any way to achieve them? For my custom shortcuts, I used the jquery keyUp event. I searched on the Internet, there is a jQuery keyUp suggestion, use the preventDefault () function. But to access my own shortcuts, I use the keyUp event. So tell me how to disable default browser shortcuts in all browsers, either using C #, or jQuery, or in any other way.

+5
source share
2 answers

This will allow you to do this:

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

checks for the presence of Ctrl + A.

 $(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 have to click in the document to focus, and then you can check it.
+6
source

You had the right procedure. I think you can use ascii values ​​to manipulate such things, for example: I use this to press the enter key.

 $('body').on('keypress', '#Selector-Id', function(e) { if (e.which == 13) { alert("Hi"); } }); 
-1
source

Source: https://habr.com/ru/post/1214061/


All Articles