Sometimes on webgl build I show text field to get some input (using html form). But when I try to input some text, it looks like Unity swallows all input. Is it possible to disable/enable it in runtime?
So, I just looked into the example provided in #658342.
By default, emscripten will capture all keyboard input on the page. This makes sense, as it means that the common simple case of having a game on a page will just work without having to deal with keyboard focus and the like. However, once you want other html elements on the page to deal with input, you need to figure out some better solution. Luckily emscripten provides some options:
In the simple case that you don’t actually need keyboard input for your webgl content, you can disable it, by adding the line:
doNotCaptureKeyboard: true,
to the setup of “Module” in the generated html, for instance just after
var Module = {
If you need input in both other html and the webgl content, you have to do some more work. Unfortunately, most browsers will not allow you to have a canvas itself receive text input. So, you need to have a html element on the page which will deal with text input for you (like a div element with contentEditable=“true”):
Now, this element will be used for text input. You need to handle focus yourself, by calling document.getElementById(‘myTextInputReceiver’).focus() when your content should receive text focus.