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 !
0
0
document.body.onkeyup = function(e){
if(e.keyCode == 32){
//your code
}
}
Thank you!
0
0
Are there any code examples left?
New code examples in category Javascript