Skip to content

Commit

Permalink
fix wasd not registering when using inputWASDEmulateDirection
Browse files Browse the repository at this point in the history
  • Loading branch information
KilledByAPixel committed Jun 14, 2024
1 parent 0eff5f3 commit 01258e2
Showing 1 changed file with 24 additions and 14 deletions.
38 changes: 24 additions & 14 deletions src/engineInput.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}

///////////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 01258e2

Please sign in to comment.