I'm using the Terminal node in a scene together with some LineEdit nodes.
When the focus is on the terminal, focus will switch to other LineEdit nodes after pressing some keys (KEY_UP, KEY_DOWN, KEY_TAB).
func _gui_input(event):
_native_terminal._gui_input(event)
if event is InputEventKey and event.pressed:
# Return to bottom of scrollback buffer if we scrolled up. Ignore modifier
# keys pressed in isolation or if Ctrl+Shift modifier keys are pressed.
if (
not event.scancode in [KEY_ALT, KEY_SHIFT, KEY_CONTROL, KEY_META, KEY_MASK_CMD]
and not (event.control and event.shift)
):
_native_terminal.sb_reset()
_handle_mouse_wheel(event)
_handle_selection(event)
func _input(event):
if has_focus():
_native_terminal._gui_input(event)
if event is InputEventKey and event.pressed:
# Return to bottom of scrollback buffer if we scrolled up. Ignore modifier
# keys pressed in isolation or if Ctrl+Shift modifier keys are pressed.
if (
not event.scancode in [KEY_ALT, KEY_SHIFT, KEY_CONTROL, KEY_META, KEY_MASK_CMD]
and not (event.control and event.shift)
):
_native_terminal.sb_reset()
if event.scancode in [KEY_DOWN, KEY_UP, KEY_TAB]:
get_tree().set_input_as_handled()
_handle_mouse_wheel(event)
_handle_selection(event)
This code solves the focus switch problem, but it is not the right fix because from my tests sometimes it causes some key press to be lost.