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
and keyup
and keep a map of the ones that are down. When they're all down, fire your event.
For example: Live copy | source
var map = {68: false, 69: false, 86: false}; $(document).keydown(function(e) { if (e.keyCode in map) { map[e.keyCode] = true; if (map[68] && map[69] && map[86]) { // FIRE EVENT } } }).keyup(function(e) { if (e.keyCode in map) { map[e.keyCode] = false; } });
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.
Similar to Vega's...but simpler
var down = {}; $(document).keydown(function(e) { down[e.keyCode] = true; }).keyup(function(e) { if (down[68] && down[69] && down[86]) { alert('oh hai'); } down[e.keyCode] = false; });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With