1

Possible Duplicate:
handling ctrl + key event in IE browser

I want to use ctrl + key (any number) so that it triggers a javascript event, but if I do that then, the browser changes tab (like it is supposed to do usually).

Is there a way of doing what I would like to do?

Vinodh Velumayil
  • 742
  • 3
  • 8
  • 24

3 Answers3

2

jquery.hotkeys

https://github.com/jeresig/jquery.hotkeys

Very easy to work with keyboard events.

Muthu Kumaran
  • 17,682
  • 5
  • 47
  • 70
0

In your keydown event handler, use event.preventDefault() :

document.addEventListener("keydown", function(e) {
    if(e.keyCode >= 48 && e.keyCode < 58 && e.ctrlKey == true) {
        e.preventDefault();
    } 
}

This doesn't work in IE8 and below, however, and I can't seem to find a solution that works with attachEvent.

apsillers
  • 112,806
  • 17
  • 235
  • 239
0

Shortcut Library (5.66 Kb Standalone)

http://www.openjs.com/scripts/events/keyboard_shortcuts/

shortcut.add("Ctrl+1",function() {
    alert("Hello World!");
});