Search code examples
javascriptkeypressonkeypress

I am having problems with 3+ keys pressed


My JS mini-game don't work correctly. It only records the first two key pressed.

You can see the problem in this jsFiddle

My code is really big, I am not sure what to put here, but I think the problem is here:

document.onkeypress=function(e){
    var charCode;

    e=e||window.event;

    charCode=typeof e.which=="number"?e.which:e.keyCode;

    if((charCode>=102&&charCode<=104)||charCode==106){
        getKey(charCode==106?4:charCode-101);//F-G-H-J=1-2-3-4
    }
    return false;
};

Solution

  • Most keyboards have limits on how many simultaneous keys they can handle. Keys like shift and ctrl can often be handled on top of whatever that simultaneous limit is.