- Home /
WebGL - Module.doNotCaptureKeyboard: true or Module.keyboardListeningElement: ... NOT WORKING ANYMORE
Since the Update to the latest Unity 5 Editor version these two options do not work anymore (Module.keyboardListeningElement, Module.doNotCaptureKeyboard) .
The WebGL Canvas is always eating all the keyboard input, no matter if these options are set or not.
Built with Unity 5.0.1 before and those options worked and I was able to use Input fields, etc. in the DOM.
Built with Unity 5.1.1 now and this option isnt working anymore.
Is there any change I have missed?
Thanks for the help.
Just spent 5 hours to investigate the same hair-pulling issue. Waiting for response with you.
Answer by RSoj · Jun 25, 2015 at 12:41 PM
I have created a workaround. Still waiting for "the right way" answer though.
1) Add html input field to your page (or use the one which worked for you with Unity 5.0.1), e.g.:
<input id="WebGLKeyboardInput" type="text" name="WebGLKeyboardInput" value="" />
2) Add following javascript function to your page
hackWebGLKeyboard: function ()
{
var webGLInput = document.getElementById('WebGLKeyboardInput');
for (var i in JSEvents.eventHandlers)
{
var event = JSEvents.eventHandlers[i];
if (event.eventTypeString == 'keydown' || event.eventTypeString == 'keypress' || event.eventTypeString == 'keyup')
{
webGLInput.addEventListener(event.eventTypeString, event.eventListenerFunc, event.useCapture);
window.removeEventListener(event.eventTypeString, event.eventListenerFunc, event.useCapture);
}
}
}
3) Call the hackWebGLKeyboard() function after WebGL has been initialized (I'm calling it from Start method on MonoBehaviour in scene)
4) Any time you need to switch input to your game, call following javascript as before
document.getElementByID('WebGLKeyboardInput').focus()
Thank you a lot for the workaround.
Also waiting for a proper fix, in the Unity Issue Tracker I found the same Issue with status "Fixed in Future Release", but it was already a month old (V. 5.1.0) and there were some editor updates since then: http://issuetracker.unity3d.com/issues/donotcapturekeyboard-not-working-in-webgl
So I created a new Bug Report in the hopes it gets noticed.
Your answer
Follow this Question
Related Questions
in webgl , how to change #canvas property? 0 Answers
Need to send Secondary camera render from unity webgl to HTML5 canvas 0 Answers
Keyboard and Controller Input Not Working in WebGL 1 Answer
How to integrate HTML5 elements in Unity ? 2 Answers
New input system doesn't work on webgl build for android 0 Answers