Is it at all possible to combine a mixture of keypress' to fire a single event?
$(document).keyup(function(e){
if (e.keyCode == 68 && e.keyCode == 69 && e.keyCode == 86) {
alert('oh hai');
}
});
I've tried it in Chrome but the event doesn't fire.
Call me crazy but I am writing a Chrome extension and want to push D+E+V keys together to force it into a hidden developer mode.
Use this code to have an event triggered by multiple key presses + Timeout after 100ms to prevent mistypes. In this example : if A,Z,E are pressed within a time period of 100ms, the event will be triggered.
I have answer from T.J. Crowder in plain javascript for someone who would want to avoid Jquery.
You would need to capture the three key events separately and fire your action only after the third one.
There's a number of ways to do this of course. This example doesn't require you to hold the keys down simultaneously, just that you type them in order: d e v.
If you used this, you might want to augment it to clear the
pressed
flags after some time interval.Here's a working example.
Disclaimer: I realize the original question said that the keys should be "pressed together". This is just an alternative as other answerers have already provided sufficient solutions for the keys being pressed together.
Similar to Vega's...but simpler
A bit more modern solution, takes advantage of arrow functions and rest parameters:
if I well understood : example fiddle, http://jsfiddle.net/gAtTk/ (look at your js console)
this code will let you enter the word "
dev
" (and in this example, at the end the eventkeyup
is removed)