I have a LineEdit that I wish would mark the keyboard-related events as handled after it has done its LineEdit things, namely add the typed character to itself, manage the caret, etc.
Currently, the nodes in the scene do receive the keyboard events in _unhandled_input(), and I wish they would not.
I’ve started pretty much reimplementing LineEdit in its _gui_input(), and having to do so does not bother me too much.
My question is : am I missing a simpler option?
Simple setup
A simple setup to see my issue would be a scenetree like this:
Node2D
--- LineEdit
--- Node2D_with_test_script
And the test script attached to Node2D_with_test_script:
With “an_action” assigned to a key associated with a symbol, like the “A” key.
My end goal is that when I click the A key and the LineEdit has focus (and edit mode), “an_action received” is never printed, but the LineEdit gets filled with "a"s.
What quickly comes to mind is adding an acceptsInput boolean to your input handler, only process input if it is true, then simply toggle it off and on when the LineEdit gains and looses focus using the editing_toggled signal.
The LineEdit only process and accept pressed key events. The release key events will continue being propagated.
The function InputEvent.is_action() just checks if the event matches one of the defined actions. A released event will also return true when checking if it’s an action.
So, you’ll need to take that into account by doing one of the following:
I thought about it, but I didn’t want to use this approach because it seemed like something that’s handled natively by Godot with accept_event() and the focus system of the UI.
As with many problems the issue was under my nose . Using is_action() was a mistake on my part in this situation.