Hello WebGL experts,
We’ve got a Unity game with a WebGL export. Currently running Unity 2018.2.12f1 with the WebGL WebAssembly export. Unfortunately we’ve run into a semi-rare issue in that when we call Input.GetKey() sometimes it looks like the key is held down, when in fact it is up on the physical keyboard.
Looking at the javascript for this, it seems that because the raw javascript only gives you keydown and keyup events that various javascript libraries have attempted to work around this by detecting/overriding keys that have been down for too long etc. However, it seems to us that Unity’s webGL export doesn’t do some of the fanciness that these libraries do.
In particular, you’ll be playing the game and using WASD or arrow keys and running around. Without changing focus sometimes a key you were pressing gets stuck in the down state.
Has anyone else run into this? Do you have a workaround? I’ve seen other Unity WebGL exports (zombsroyale.io) also have this problem with the keyboard getting stuck and it can be frustrating in a competitive game. At this point I’m looking at calling out to a jslib in our WebGL build that listens to the document level keydown and keyup events, but also catches a few other events to ensure that they javascript keyboard state stays as good as possible. Is there a better solution?
Any ideas/help would be greatly appreciated.
Thanks!