Suppose your scene tree is configured as follows and you want to toggle the child2’s visibility
yourparent
child1
child2
By following this tutorial on input handling, it will help explain how to process a key press. This can be done as follows in the ‘yourparent’ node’s script, where every frame we check if a key (in this example, the enter key, which is mapped to the ‘ui_accep’ input event string) is pressed and call a function to toggle the visibility when the key is pressed
func _process(delta):
if Input.is_action_just_pressed("ui_accept"):
_on_toggle_child_visibility()
func _on_toggle_child_visibility():
var yourChild= get_node("child1/child2")
yourChild.visible = not yourChild.visible #toggle visibility