2

How can we use Keyboard shortcut for MVC application?. My requirement is when I press Ctrl+U , I want to load my home page and when I press Ctrl+T, nedd to open another page. How it is possible in client side. Please help.

Regards Sreyas MN

Sreyas MN
  • 49
  • 2
  • 8
  • Correct me if I am wrong, ASP.NET MVC has no built-in keyboard short cuts, you will need to use jQuery or JavaScript to capture these events and wire them to some event handler – Julius Depulla Nov 26 '15 at 21:59
  • Possible duplicate of [Simplest way to detect keypresses in javascript](http://stackoverflow.com/questions/16089421/simplest-way-to-detect-keypresses-in-javascript) – kayess Nov 28 '15 at 16:30

3 Answers3

2

Capture the Events via Javascript.

KeyCode for Ctrl+U and Ctrl+ T using below code

$(document).bind('Keydown',function(event){
if(event.KeyCode== Keycode) // check for Keycode for Ctrl+U and Ctrl+ T
{
window.location.href(url);
}
});

use target="_blank" to open in new tab.

er_Yasar
  • 150
  • 10
0

Just capture keyboard events on client script, when your desired key combinations fire redirect your code execution to the desired controllers with location.href

Bardo
  • 2,470
  • 2
  • 24
  • 42
0

You can use jquery hotkeys

jQuery Hotkeys supporting almost any key combination.

$(document).bind('keydown', 'Ctrl+T', function(){ 

// Do what ever youwant 

});