Skip to content

Commit

Permalink
Allow user to use keyboard for game
Browse files Browse the repository at this point in the history
  • Loading branch information
Anushri255 committed Aug 11, 2024
1 parent bed492a commit 606c246
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ping-pong.html
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,21 @@
}
}

function keyDownHandler(e) {
if (e.key === 'Right' || e.key === 'ArrowRight') {
rightPressed = true;
} else if (e.key === 'Left' || e.key === 'ArrowLeft') {
leftPressed = true;
}
}

function keyUpHandler(e) {
if (e.key === 'Right' || e.key === 'ArrowRight') {
rightPressed = false;
} else if (e.key === 'Left' || e.key === 'ArrowLeft') {
leftPressed = false;
}
}


</script>
Expand Down

0 comments on commit 606c246

Please sign in to comment.