My code works without problems on IE9/IE10, FF, Chrome and opera but on older Internet Explorer no Keyboard input is handled.
I have the following code for handling events. It should only fire when a new button is pressed.
lastEvent = void 0;
heldKeys = {};
window.onkeydown = function(event) {
if (lastEvent && lastEvent.keyCode === event.keyCode) {
return;
}
lastEvent = event;
heldKeys[event.keyCode] = true;
switch (event.which) {
case 80:
return myamp.userInput("positiv");
case 81:
return myamp.userInput("negativ");
}
};
window.onkeyup = function(event) {
lastEvent = null;
return delete heldKeys[event.keyCode];
};
Try
I tried different solutions but these still did not work correctly in IE8. What I came up with that worked is this:
You need to bind to the document, not window.
needs to be
You have to use normalized key code. Like this: