godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91k stars 21.17k forks source link

spinBox doesnt detect Keys #95793

Closed jonSP12 closed 1 month ago

jonSP12 commented 2 months ago

Tested versions

4.3 stable

System information

windows 10

Issue description

https://github.com/godotengine/godot/issues/43701

spinBox node doesnt detect key inputs on signal gui input( event: InputEvent ) "Emitted when node receives an Input Event"

Steps to reproduce

make a plugIN add an instance with a spinBox node with the signal gui input

func _on_spin_box_gui_input(event: InputEvent) -> void:
    if event is InputEventKey:
        print(event)
        if event.scancode == KEY_ENTER && event.pressed:
            print("666666666666666666666666666666")

It only reads mouse inputs when:

func _on_spin_box_gui_input(event: InputEvent) -> void:
    print(event)

Minimal reproduction project (MRP)

spinbox.zip

addmix commented 2 months ago

It's my understanding that _gui_input() is dedicated to mouse inputs on specific GUI elements. I think this is a documentation issue rather than a bug.

jonSP12 commented 2 months ago

It also doesnt receive the signal focus entered() https://github.com/godotengine/godot/issues/43338

only the mouse enter() seems to work This is a little weird since the godot editor / node inspector, is full of tiny boxes that receive floats inputs, such has position / offset / size / shader paramenter..etc...

timothyqiu commented 2 months ago

It's because the internal LineEdit handles that key press, so the event won't be propagated to SpinBox.

So you should get the LineEdit with get_line_edit() and listen to its gui_input signal instead. You can also use the text_submitted instead if you only want the enter key pressed event.

jonSP12 commented 2 months ago

It's because the internal LineEdit handles that key press, so the event won't be propagated to SpinBox.

So you should get the LineEdit with get_line_edit() and listen to its gui_input signal instead. You can also use the text_submitted instead if you only want the enter key pressed event.

Yes... but i my case get_line_edit() always returns null ?!?! Cannot connect to 'focus_entered': the provided callable is null.

@onready var spinBx = get_node_or_null("../../../../C_OP/SpinBox");
var spinBx2;

func _ready():
    spinBx2 = spinBx.get_line_edit();
    spinBx2.connect("focus_entered", self, "spinBx2_on_focus_entered");
    spinBx2.connect("focus_exited()", self, "spinBx2_on_focus_exited");

I just cant understand this ?

AThousandShips commented 2 months ago

Did you mean this as your code:

@onready var spinBx = get_node_or_null("../../../../C_OP/SpinBox");
var spinBx2;

func _ready():
    spinBx2 = spinBx.get_line_edit();
    spinBx2.focus_entered.connect(spinBx2_on_focus_entered);
    spinBx2.focus_exited.connect(spinBx2_on_focus_exited);

Your code isn't valid 4.x code

jonSP12 commented 2 months ago

thanks it works now