Keyboard Controls controlling webpage too?

Hi, anyone knows how can you make sure the keyboard control in game doesn’t control the webpage itself?

I have my game on a webpage and when I am using keys like up and down for the game, it also controls or scroll the webpage up and down as well.

Is there a way to stop or prevent the webpage to listen to the keyboard controls used in Phaser?

Thanks

Hi, try adding event.preventDefault(); to your callback function.

For example:

  this.cursors = this.input.keyboard.createCursorKeys();

  this.cursors.up.on(
    "down",
    function(key, event) {
      event.preventDefault();
      // .. do your thing
    },
    this
  );

Thanks!

input.keyboard.addCapture()

1 Like