We have an issue managing Keyboard/Mouse events in our WebGL module, as our application is in a canvas among other elements in the page. We want input forwarded to WebGL module only when its canvas has focus.
In 5.6 you should still be able to access JSEvents from a Javascript plugin. If you are trying to access it from the global namespace, you should explicitly specify which instance of the game you are referencing to. If your build is instantiated as MyGameInstance, then you can try MyGameInstance.Module.JSEvents and check if it works as you expect (note that from inside your build you can still access the JSEvents object directly). If this does not resolve your issue, provide your exact Unity version and a link to your build if possible.
I think you should be able to reproduce it with any WebAssembly build. Sending you a package could be complicated in this context. Let’s go there only if we really need to
Yes, you are right, JSEvents is not exported anymore. Though it should be easy to make it available. Simply add the following Assets/Plugins/JSEvents.jspre file to your project:Module.getJSEvents = function () { return JSEvents; };Now it should work:
This is a good demonstration of how to use the new framework namespace in 5.6. Objects, previously residing in the global namespace, are now local to the build code and can be directly accessed from Javascript plugins. This way you are now able to embed more than one game on the page without causing conflicts in the global namespace (as well as not causing conflicts with the page code itself).
Hey, the Assets/Plugins/JSEvents.jspre file does not appear to exist anymore in Unity 5.6.3f1. Is there any other work around for this, as I need to be able to have keyboard input within the game and also on HTML input elements on the webpage, thanks.
FYI, if anyone is having issues with getting the canvas to catch keyboard events when WebGLInput.captureAllKeyboardInput = false, try adding the attribute: tabindex=‘1’ to the canvas element. That did the trick for me.
Not sure why it works through, do keyboard events only go to things that can get focus? Is something having a tabindex a requirement to be “focusable”?
You might also want to hide that input field, but still let it receive focus. This is is the best way I found to do that. Tested on Chrome and Firefox: