Answers for "javascript knowing when space is pressed"

1

javascript knowing when space is pressed

// event = keyup or keydown
document.addEventListener('keyup', event => {
  if (event.code === 'Space') {
    console.log('Space pressed'); //whatever you want to do when space is pressed
  }
})
//don't forget to upvote answers that help you !
Posted by: Guest on November-28-2020
1

execute JS code after pressing space bar

document.body.onkeyup = function(e){
    if(e.keyCode == 32){
        //your code
    }
}
Posted by: Guest on June-19-2020

Code answers related to "javascript knowing when space is pressed"

Code answers related to "Javascript"

Browse Popular Code Answers by Language