Skip to content

Commit

Permalink
Merge pull request #1 from julienw/support-wasd
Browse files Browse the repository at this point in the history
Gives support for the WASD keys -- AZERTY-friendly
  • Loading branch information
end3r authored Oct 31, 2016
2 parents 2002443 + 100f5aa commit 636a3b8
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,35 @@
document.addEventListener("keydown", keyDownHandler, false);
document.addEventListener("keyup", keyUpHandler, false);
function keyDownHandler(e) {
if ("code" in e) {
switch(e.code) {
case "Unidentified":
break;
case "ArrowRight":
case "Right": // IE <= 9 and FF <= 36
case "KeyD":
rightPressed = true;
return;
case "ArrowLeft":
case "Left": // IE <= 9 and FF <= 36
case "KeyA":
leftPressed = true;
return;
case "ArrowUp":
case "Up": // IE <= 9 and FF <= 36
case "KeyW":
upPressed = true;
return;
case "ArrowDown":
case "Down": // IE <= 9 and FF <= 36
case "KeyS":
downPressed = true;
return;
default:
return;
}
}

if(e.keyCode == 39) {
rightPressed = true;
}
Expand All @@ -43,6 +72,35 @@
}
}
function keyUpHandler(e) {
if ("code" in e) {
switch(e.code) {
case "Unidentified":
break;
case "ArrowRight":
case "Right": // IE <= 9 and FF <= 36
case "KeyD":
rightPressed = false;
return;
case "ArrowLeft":
case "Left": // IE <= 9 and FF <= 36
case "KeyA":
leftPressed = false;
return;
case "ArrowUp":
case "Up": // IE <= 9 and FF <= 36
case "KeyW":
upPressed = false;
return;
case "ArrowDown":
case "Down": // IE <= 9 and FF <= 36
case "KeyS":
downPressed = false;
return;
default:
return;
}
}

if(e.keyCode == 39) {
rightPressed = false;
}
Expand Down Expand Up @@ -185,4 +243,4 @@
<div id="output"></div>

</body>
</html>
</html>

0 comments on commit 636a3b8

Please sign in to comment.