pmgl / microstudio

Free, open source game engine online
MIT License
932 stars 106 forks source link

alt-tabbing out of the game locks ALT in pressed state #193

Open Skaruts opened 1 year ago

Skaruts commented 1 year ago

When you alt-tab out of the game, both keyboard.ALT and keyboard.ALT_LEFT get locked in pressed state. This happens both in the browser and in the standalone version.

I'm on windows 7, using Brave browser.

It's easy to replicate:

update = function()
  print(keyboard.ALT)
end

Do that, run the game and alt-tab away, and when you come back the console will be printing 1.

(Also happens with the game paused.)

JmeJuniper commented 1 year ago

This isn't fixable on microstudio's end, I don't believe, it happens to everything (that is, holding down a key when you switch to a different tab causes the key to stay held). The way to fix it is just to hit alt again. However, if the print statement is activating while the game is paused, that seems like a real bug? Unless I misunderstood what you are saying, which is likely XD

Skaruts commented 1 year ago

I was thinking there might be something in JS that detects when the game loses focus, and if so, maybe it can then make sure input isn't being wrongly received. I could be wrong. Usually engines can detect that, but I've no idea when it comes to JS.

(In fact, not just alt-tabbing, you can hold any key and click outside the game view, and that key will be locked in pressed state.)

About the pause thing, I'm not quite being able to reproduce it now. But just to be clear, I was talking about when you pause it in the code tab.

Skaruts commented 1 year ago

This also happens in the sprite editor, when you alt-tab away. When you get back, sometimes you are stuck in the eye dropper tool until you press alt to get rid of it.