I am a beginner coder in my high school programming class, I am currently trying to edit a HTML/Javascript game I found online and I would like to update a function called acceleration:
function accelerate(n) {
myGamePiece.gravity = n;
}
with a keypress or keydown/up event. What it would do is make a box accelerate up or down whether the spacebar is pressed. The issue is the only good event listener examples I can find use buttons, and the game currently works using an acceleration button:
<button onClick="" onkeydown="accelerate(-.5)" onkeyup="accelerate(.5)">Start Game</button>
The issue is that I want the window / document (I don't know which it is) to detect if the user is inputting the spacebar key and to update the acceleration function accordingly. I would very much appreciate any help anyone would be willing to give, thank you :D