Can jQuery .keypress() detect more than one key at the same time?

In order to detect multiple keys being held down, use the keydown and keyup events.

var keys = {};

$(document).keydown(function (e) {
    keys[e.which] = true;
});

$(document).keyup(function (e) {
    delete keys[e.which];
});

I’ve put together a demo here: http://jsfiddle.net/gFcuU/. It’s kind of fun, though I noticed my keyboard is only able to detect at most 6 keys.

Leave a Comment