isKeyPressed remains in state if you tab to URL bar

Recommended Posts

I have a peculiar issue: if you accidentally hit tab in browser in game, it tabs to the URL bar as the next Browser element in line.

What this means for MelonJS is if you were pressing a bound key, e.g., me.input.KEY.DOWN, at the time of tabbing, me.input.isKeyPressed('down') would remain true even if you're no longer pressing the key after focusing back on the game.

1) Why does this happen when you blur the game's focus?

2) How can I ensure isKeyPressed('down') is updated to current state onFocus into game?


@obiot @Parasyte

Share this post

Link to post
Share on other sites

well that's an interesting one too, I was just looking at the code and indeed there is nothing to manage key status when the window/browser is losing status.

So two solutions to that :

  1. you can disable the pauseOnBlur feature (true by default), which means the game won't pause when the window will loose focus, and that the keys will properly "behave"
  2. or (and this is what I would do in melonJS to fix this), is to register on the state pause or resume event (that are called when the window is losing/regaining focus) and simulate the required keydown or registered keys using `triggerKeyEvent(YOU_KEY, false)

these are more workaround, but at least they won't conflict with a later fix in melonJS

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.