Search Unity

Locking Keyboard Focus on Input Field

Discussion in 'UGUI & TextMesh Pro' started by annieshi, Feb 3, 2020.

  1. annieshi

    annieshi

    Joined:
    Aug 28, 2019
    Posts:
    1
    Hi!

    I was wondering if there was a simple or straightforward way to lock keyboard input focus when using an Input Field? For example, in my program, if you click the letter "L", it will trigger command X to fire. Then, when I click my Input Field to enter some text that includes the letter "L", it will also trigger command X to fire. Instead, I would like ignore all keycode inputs when typing in an input field, and then turn them back on when I exit the input field.

    The only current workaround I can think of is having some global bool indicating whether the user is currently typing into an input field or not, and checking that bool before firing off keycode commands in every script that detects for a keycode command. This seems inefficient - is there a simpler way to do this built-in?

    I also want to avoid using onGUI (I know they have some focuscontrol options) - my input fields and other UI components need to be preexisting.

    Thank you!
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,836
    I don't think there is a simpler way to do that.