Jump to content

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

Link to comment
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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Create New...