I've created a lame car game in which by clicking a button an image of a car moves to the right a little each time. But now I want to trigger the button by pressing a key. I've used onKeypress and placed it inside the button tag but it isn't working. I tried to figure it out on my own but unfortunately couldn't wrack up the logic for it. Can you guys help me out with this, please?
<div id="racetrack"><img id="user" src="ferrari.jpg"></div>
<button id="pedal" onkeypress="moveCar()">Pedal</button>
function moveCar(){
var car = document.getElementById("user");
var marginLeft = car.style.marginLeft == "" ? "0px" : car.style.marginLeft;
car.style.marginLeft = parseInt(marginLeft) + 100 + "px";