Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

How to disable keyboard interaction with UI?

Discussion in 'UGUI & TextMesh Pro' started by m9_psy, Sep 3, 2014.

  1. m9_psy

    m9_psy

    Joined:
    Jul 27, 2014
    Posts:
    10
    Setting navigation option to None does not help.
     
    BMRG14 likes this.
  2. Senshi

    Senshi

    Joined:
    Oct 3, 2010
    Posts:
    557
  3. m9_psy

    m9_psy

    Joined:
    Jul 27, 2014
    Posts:
    10
    That answer does not help me. We can't simply clean fields in Standalone Input Module. If we do this, ui will be broken and a lot of errors appear. I cant set them to null, or to anything except Horizontal etc. Deleting EventSystem does not help too.
     
  4. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    Try:

    EventSystemManager.currentSystem.currentInputModule.DeactivateModule();
     
  5. m9_psy

    m9_psy

    Joined:
    Jul 27, 2014
    Posts:
    10
    This does not help too. If i do this in Start method, Null reference exception throwed. When i execute it Update, UI deactivates completely and when i press any button, Null reference exception throwed again. Currently for me its very weird behavior. May be it is navigation bug or something similar?
     
  6. Tim-C

    Tim-C

    Unity Technologies

    Joined:
    Feb 6, 2010
    Posts:
    2,183
    The inbuilt input module is designed to work with keyboard input. If you want to not have keyboard input you can either modify the existing StandalonInputModule or write a custom module that does not support keyboards.
     
  7. m9_psy

    m9_psy

    Joined:
    Jul 27, 2014
    Posts:
    10
    Is standart module similar to https://gist.github.com/stramit/ce455682b7944bdff0e7?

    Anyway i cant get it work, because of missing script error after i set this script instead of builtin. Would you be so kind to provide an example?
     
    Last edited: Sep 4, 2014
  8. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    Not the cleanest way, but it works:
    I just derived StandaloneInputModule and removed Keyboard stuff from Process method
     

    Attached Files:

    m9_psy and Senshi like this.
  9. m9_psy

    m9_psy

    Joined:
    Jul 27, 2014
    Posts:
    10
    Yes, this script solve the problem, thank you.
     
  10. futurecrayon

    futurecrayon

    Joined:
    May 7, 2014
    Posts:
    14
    defaxer's NoKeyboardInputModule.cs script was working for me (thanks!), but broke when I updated to beta 19.

    Stupid question, but I'm not sure how to view the current StandaloneInputModule.cs so that I can derive/override its functionality.
     
  11. Dampire

    Dampire

    Joined:
    Jan 18, 2014
    Posts:
    7
    Bump. Where i can get b20 version of StandaloneInputModule.cs. Too many undocumented changes, I can't fix previous module.
     
  12. defaxer

    defaxer

    Joined:
    Nov 15, 2010
    Posts:
    140
    I may be wrong, but you have to change:

    var pointerData = GetMousePointerEventData();
    with
    var pointerData = GetMousePointerEventData()[PointerEventData.InputButton.Left].buttonData;
    in ProcessMouseEvent method() (Line 28)
     
  13. rakkarage

    rakkarage

    Joined:
    Feb 3, 2014
    Posts:
    683
    the interactable check box also seems to work?
    or maybe not... just lost focus i guess idk
     
  14. futurecrayon

    futurecrayon

    Joined:
    May 7, 2014
    Posts:
    14
    I finally found out how to disable keyboard interaction in beta 20 without writing your own input module (to replace StandaloneInputModule).

    You have to uncheck the "Send Navigation Events" checkbox on the Event System component of your EventSystem scene object.

    For what it's worth, before I found this solution, I found out how to view StandaloneInputModule.cs. In MonoDevelop, you can have to navigate to UnityEngine.UI.dll from the Solution browser (typically it's under Assembly-CSharp -> References). Viewing UnityEngine.UI.dll in the Assembly Browser, you can navigate to UnityEngine.UI -> UnityEngine.EventSystems -> StandaloneInputModule. Using this source, I wrote a new "no keyboard" input module similar to defaxer's (upthread) and it seemed to work (even though I was way out of my depth). But I'm much more comfortable with the simpler solution above.
     
    tjPark, jcenzano, Kokowolo and 2 others like this.
  15. xanat0s

    xanat0s

    Joined:
    Nov 20, 2014
    Posts:
    10
    That's the solution I stumbled over as well. According to the docs, it's exactly what that field is there for. (See Send Navigation Events.)

    It can be toggled via script like so:
    Code (CSharp):
    1. UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents = !UnityEngine.EventSystems.EventSystem.current.sendNavigationEvents;
     
    BMRG14 and BCook99 like this.
  16. Leonard-Walker

    Leonard-Walker

    Joined:
    Oct 31, 2012
    Posts:
    14
    Here is an update Version of the Mouse Only Input Script
     

    Attached Files:

  17. Hauthorn

    Hauthorn

    Joined:
    May 11, 2015
    Posts:
    3
    Is it not enough to to simply disable the "Send Navigation Events" on the Event System manager component?
     
    Last edited: May 6, 2017