From 100f5aab6062bf4f5d382afb1b43969b5cddf3ee Mon Sep 17 00:00:00 2001 From: Julien Wajsberg Date: Mon, 31 Oct 2016 15:16:35 +0100 Subject: [PATCH] Gives support for the WASD keys -- AZERTY-friendly --- index.html | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/index.html b/index.html index 98058ce..b1bf881 100644 --- a/index.html +++ b/index.html @@ -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; } @@ -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; } @@ -185,4 +243,4 @@
- \ No newline at end of file +