Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags

Spacebar is scrolling itch page

A topic by skeddles created Jul 24, 2021 Views: 186 Replies: 1
Viewing posts 1 to 2
(2 edits)

I have embedded my web game, but when the user presses the spacebar, the entire page scrolls. The alt key also doesn't not prevent default properly.

I have this on my game:

document.addEventListener('keyup', e => {         
    e.preventDefault();         
    e.stopPropagation();         
    e.stopImmediatePropagation();         
    handleInput(e);         
    return false;     
});

But it does nothing and the page still scrolls down. Please to help.

(+2)

Figured it out, turns out you need to do it on keydown as well:

window.addEventListener('keydown', e => e.preventDefault());
window.addEventListener('keyup', e => e.preventDefault());
This topic has been auto-archived and can no longer be posted in because there haven't been any posts in a while.