From 01258e2d4c3c58556181c07f27d2be58096e0d6a Mon Sep 17 00:00:00 2001 From: Frank Force Date: Thu, 13 Jun 2024 20:31:31 -0500 Subject: [PATCH] fix wasd not registering when using inputWASDEmulateDirection --- src/engineInput.js | 38 ++++++++++++++++++++++++-------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/src/engineInput.js b/src/engineInput.js index 0caf684b..fab2116a 100644 --- a/src/engineInput.js +++ b/src/engineInput.js @@ -146,23 +146,33 @@ function inputUpdatePost() /////////////////////////////////////////////////////////////////////////////// // Keyboard event handlers -onkeydown = (e)=> { - if (debug && e.target != document.body) return; - e.repeat || (inputData[isUsingGamepad = 0][remapKey(e.which)] = 3); - preventDefaultInput && e.preventDefault(); -} + onkeydown = (e)=> + { + if (debug && e.target != document.body) return; + if (!e.repeat) + { + inputData[isUsingGamepad = 0][e.which] = 3; + if (inputWASDEmulateDirection) + inputData[0][remapKey(e.which)] = 3; + } + preventDefaultInput && e.preventDefault(); + } -onkeyup = (e)=> -{ - if (debug && e.target != document.body) return; - inputData[0][remapKey(e.which)] = 4; -} + onkeyup = (e)=> + { + if (debug && e.target != document.body) return; + inputData[0][e.which] = 4; + if (inputWASDEmulateDirection) + inputData[0][remapKey(e.which)] = 4; + } -function remapKey(c) -{ - return inputWASDEmulateDirection ? - c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c; + // handle remapping wasd keys to directions + function remapKey(c) + { + return inputWASDEmulateDirection ? + c==87?38 : c==83?40 : c==65?37 : c==68?39 : c : c; + } } ///////////////////////////////////////////////////////////////////////////////