Search Unity

Block keyboard input during text input

Discussion in 'Input System' started by peaj_metric, Mar 15, 2020.

Thread Status:
Not open for further replies.
  1. peaj_metric

    peaj_metric

    Joined:
    Sep 15, 2014
    Posts:
    146
    What is the recommended way to block keyboard input as long as a UI input field is focused?
    For example if I would like to block WASD movement in a game as soon as long as the chat is open.

    The most obvious solution would be to disable/switch the Actionmap but that would not block input from public InputAction fields in MonoBehaviours and it would also block Gamepad input.

    The optimal solution would be to lock keyboard input to the textinput field and block it from executing actions.
    Is this possible?

    Thanks,
    Pascal
     
  2. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    This should be handled by the UI input module internally and automatically. Added an internal ticket for this (ISX-340) and will get this looked at.

    The by far simplest way ATM to silence keyboard input is to just disable the keyboard device outright.

    Code (CSharp):
    1. InputSystem.DisableDevice(Keyboard.current);
    2.  
    3. // To re-enable.
    4. InputSystem.EnableDevice(Keyboard.current);
     
    Last edited: Mar 16, 2020
  3. peaj_metric

    peaj_metric

    Joined:
    Sep 15, 2014
    Posts:
    146
    Great this is exactly what I was looking for (I hope it still registers text input when disabled)
    Was looking for sth like "Keyboard.current.SetActive". Seems I was looking at the wrong class...

    Regarding the input module: I am still using the default UI input module and besides the Input field is selected via script.
    So I guess it might work with the new Input System Input Module.
    I will have a try at this.

    Thanks,
    Pascal
     
  4. Rene-Damm

    Rene-Damm

    Joined:
    Sep 15, 2012
    Posts:
    1,779
    Yup, it will.

    ATM we have the unfortunate situation that text input in uGUI other than through IME is actually not going through the UI input module at all but rather picked up directly from the native Unity runtime. We're working with the UI team to resolve this and to give the input module a means of knowing when the UI is consuming text input.
     
  5. PropolisSpray

    PropolisSpray

    Joined:
    Jun 23, 2022
    Posts:
    4
    hello, there.
    how's this topic goin' ?
     
    Neiist likes this.
  6. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Please don't necro posts for such a pointless reason.
     
    Boof and coatline like this.
Thread Status:
Not open for further replies.