DEV Community

Khalid shammout
Khalid shammout

Posted on

Js On Key Press???

want to create a game or a function that runs when a key is pressed, it's so easy just do those easy steps:

1- copy this code:

document.body.onkeydown = function (e) {
    if (e.keyCode == 39) { // right arrow
        //code here
Enter fullscreen mode Exit fullscreen mode

2- change the key code:
use to get the keycode you want

3- enjoy😎

Discussion (0)