0 votes

I have a screen with many different controls. I have the 'N' key set to open a note taking window. Normally it works fine, except when I try to hit 'N' after making a selection on a option button. After that selection, no keystrokes are noticed. I am assuming it is a focus issue. I have put around focus_owner = get_focus_owner() in a few places and then done:

func _on_StarListButton_focus_exited():
    focus_owner.grab_focus()

to try and restore focus to the keyboard. I even tried to

func _unhandled_input(event):
    focus_owner.grab_focus()

nothing seem to restore the ability to capture a keystroke? Any ideas?

Godot version v3.5.1.stable.official [6fed1ffa3]
in Engine by (98 points)

1 Answer

+1 vote
Best answer

I was looking up some info on this one, it looks like there’s also a release_focus() function. You might try setting up some type of signal or automation to release the focus on the button and then perhaps grab focus on the parent element or node you want to refocus.

Maybe this will be useful: https://godotforums.org/d/22920-how-to-remove-focus-from-control-nodes/4

Hopefully this helps! Otherwise I could try to hop in and recreate the issue in Godot

by (135 points)
selected by

Awesome! The code below did the trick. Thanks for the help!

func _unhandled_input(event):
    var current_focus_control = get_focus_owner()
    if current_focus_control:
        current_focus_control.release_focus()
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.