Answers ( 1 )

  1. 2017-01-07 20:01

    You have to change the event type to keydown, and check for the spacebars keycode which is 32.

    Here is an example of what that would look like:

    window.addEventListener('keydown', function(e) {
      if (e.keyCode == 32) {
        console.log('Spacebar pressed');
      }
    });
    
◀ Go back