How do I hide or show a TextInput object with a key

Not favoritedFavorited Favorited 0 favourites
  • 7 posts
From the Asset Store
Hand-painted tiles, objects, animated objects, and background to build a colorful Mayan civilization environment.
  • I want to display a TextInput object in game when I press the ` key, and hide it when I press ` again.

    I tried this, but it doesn't work.

    I also tried putting it on an HTML layer, still doesn't work

    What should I do?

    When I have focus on the TextInput, I can't press ` to hide it again.

    Tagged:

  • If I understood correctly… just add a instance boolean var to the TextInput ("enable", false by default) and do this.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • If I understood correctly… just add a instance boolean var to the TextInput ("enable", false by default) and do this.

    This will not work if you have already typing in the TextInput.

  • I admit it's a little bit sketchy.

    The trigger one is needed because by pressing ' it will be pressed longer than only one game loop and it seems you can only do (un)focus or make it (in)visible. So you need more than on event.

    If the key ' is pressed with a shift key you need to release both keys before pressing it again. Otherwise it won't recognized

  • > If I understood correctly… just add a instance boolean var to the TextInput ("enable", false by default) and do this.

    This will not work if you have already typing in the TextInput.

    Try doing something kinda hacky like this. (replace the "\" with the desired key)

  • You are running into an edge case.

    When the focus is on the TextInput, then the Keyboard object no longer handles keyboard input, instead Construct is allowing the browser to take control. Handling the interaction between the keyboard and a text input is surprisingly difficult (if you want it to work as users expect it should work that is), so instead of reinventing the wheel, we just let the browser do it's thing and for most cases it's the right thing to do, just let the user type normally.

    To do what you describe, you have to get a little bit clever though...

    The first thing I noticed is that after making the input visible, focusing it wasn't working for me, so I included a very short wait to make sure it worked.

    The unintuitive part is hiding the input, to do so I did a couple of things:

    1. Use a trigger that responds to changes in the input.
    2. Use a regular expression to check if the last character of the input is the one I am interested in. In this case the regular expression "'$" does just that. The $ is checking it is the end of the string. "gi" are regular expression flags indicating the match should be global (g) and case insensitive (i), I don't think any of those matter for this contrived example.
    3. Make sure to remove the "'" from the string in the action block, because I imagine you don't want it to be written in the text input.
  • Thanks to everyone for answers!

Jump to:
Active Users
There are 0 visitors browsing this topic (0 users and 0 guests)