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.
If you want to detect that the d, e, and v keys were all down at the same time, you have to watch both
keydown
andkeyup
and keep a map of the ones that are down. When they're all down, fire your event.For example: Live copy | source
I assume you don't care what order they're pressed down in (as that would be a pain to reliably press) as long as they're all down at the same time at some point.
You should use the keydown and keyup events, to handle more then one key "at the same time".
Perhaps a simpler key combination would be easier?
How about something like Shift + Alt + D? (You probably shouldn't use the Control key because most browsers already interpret Ctrl+D in one way or another)
The code for this would be something like this:
I tried the three top answers (as of this post), and none of them worked for me. They didn't reset the keys.
If it took 3 keys fire the script, after firing it once - pressing any one of the 3 keys would fire it again.
I just wrote this script and it's working very well. It uses Shift+S to fire, but you can easily change that. It resets after pressing the combination.
Fiddle: http://jsfiddle.net/9m8yswwo/13/
https://github.com/JesseBuesking/jquery.hotkeys.extended
Check this out. You might be looking for this.
We can trigger a function on multiple key press. eg: p+t+k
maybe your looking for this.
If you care about the order and also need to hold a key and tap another (ex: Shift + DEL, DEL, DEL...), without having to lift up on the first key to get the event to fire again... I've modified @BlakePlumm's [fiddle] comment which extended @lu1s' comment on @ParthThakkar's answer.
Also, using jQuery's .on() allows you to listen for the key sequence only on certain elements. Change 'body' to 'input.selector' or whatever else.
Additional thoughts: If you only kinda care about the order - that is, the first keys just need to be down, as long as your main event-firing key is pressed last (stuff like CTRL+SHIFT+TAB, TAB, TAB), add this condition:
fiddle with more glorious options and live demo: - http://jsfiddle.net/kstarr/4ftL1p3k/