Search Unity

How to get rid of Unity canvas collecting all keyboard input

Discussion in 'Web' started by bracca, Sep 14, 2016.

  1. bracca

    bracca

    Joined:
    May 11, 2016
    Posts:
    11
    Hi,

    i am developing a web application in which the unity canvas is integrated into a more complex html page with regular input controls.

    Even a simple text input cannot be used because when i try to type into the text box the keyboard input goes to the webgl canvas.

    Consider this body of an html page:
    <body>
    <input type="text" name="inputtest" ><br>
    <p id="demo"></p>
    <br/>
    <canvas class="emscripten" id="canvas" oncontextmenu="event.preventDefault()" height="600px" width="960px"></canvas>
    <script type='text/javascript'>
    var Module = {
    TOTAL_MEMORY: 268435456,
    errorhandler: null, // arguments: err, url, line. This function must return 'true' if the error is handled, otherwise 'false'
    compatibilitycheck: null,
    dataUrl: "Release/buildminimal.data",
    codeUrl: "Release/buildminimal.js",
    memUrl: "Release/buildminimal.mem",
    };
    </script>
    <script src="Release/UnityLoader.js"></script>

    </body>​

    I would like to be able to type inside <input type="text" name="inputtest" > but i cannot.
    Please suggest how to perform this task?

    I read this post: http://forum.unity3d.com/threads/disable-enable-keyboard-in-runtime-webgl.286557/#post-1892527

    and tried with the "doNotCaptureKeyboard: true" technique but without success. Moreover that post is quite old so may be in the meantime some more progress has been done.
     
  2. Marco-Trivellato

    Marco-Trivellato

    Unity Technologies

    Joined:
    Jul 9, 2013
    Posts:
    1,654
  3. bracca

    bracca

    Joined:
    May 11, 2016
    Posts:
    11
    Thanks,
    i managed to make my text input adding on start:
    =============
    #if !UNITY_EDITOR && UNITY_WEBGL
    WebGLInput.captureAllKeyboardInput = false;
    #endif
    =============

    anyway i still have problem: while i can type in the textarea i cannot select the inputed text with the mouse (to perform for example". double click to select and DEL to delete. I can succesfully use backspace to delete, but being not able to select the text makes the webpage "behaving strangely" for a normal website user.

    Is there a way to enable selecting the text typed inside <input type="text" name="inputtest" > again?

    Thanks.
     
  4. wurzel-digital

    wurzel-digital

    Joined:
    Jun 21, 2013
    Posts:
    9
    Setting
    Code (CSharp):
    1. WebGLInput.captureAllKeyboardInput = false;
    seem to have helped a lot of developers. It didn't help us. We have a <div> dynamically filled by Javascript placed on top of the Unity #canvas and Unity still gobbles up all keyboard events.
     
  5. chemara

    chemara

    Joined:
    Nov 9, 2017
    Posts:
    3
    same issue i am facing as @bracca mentioned, has anyone got the solution?

    my unity webgl application is embedded in webpage using react-unity-webgl
    i want to provide keyboard access to other html component on my webpage, but while i load unity webgl app, it hold the keyboard access forever and i am not able to input anything in my other webpage component.

    also if i unload unity webgl app and if start typing anything in input tags on my webpage, it starts throwing below error

    upload_2022-9-22_23-23-52.png