Aakash Chakravarthy
Aakash Chakravarthy

Reputation: 10701

Javascript multiple keys code

How to get multiple keys code ?

i.e for Ctrl+g what is the key code ?

The key code for ctrl is 17 and for g is 71. Should i use the key code 88 (17+71) for ctrl+g ?

or for shift+alt+1 etc

Any suggestions, is this possible ? I am using jquery and is there any plugin for this ?

☺☺☺☺

Upvotes: 2

Views: 3102

Answers (2)

Dagg Nabbit
Dagg Nabbit

Reputation: 76776

The KeyboardEvent object will have ctrlKey, shiftKey, altKey, and metaKey properties. Check that evt.ctrlKey is true. There's no need to use jQuery for this. See here for latest (DOM3) documentation: http://www.w3.org/TR/2006/WD-DOM-Level-3-Events-20060413/keyset.html#Modifiers

Upvotes: 6

rfunduk
rfunduk

Reputation: 30452

Take a look at the jQuery docs on the subject:

The event object yielded to your handler has a ctrlKey property.

So, e.g.: if( e.keyCode == 71 && e.ctrlKey ) { // ctrl+g }

Upvotes: 2

Related Questions