Popup Menu: how to trigger item IDs with the keyboard?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Macryc

Hi!
I have a RTS-type mechanic in my game with contextual popups appearing at various points and it’s kinda important that the player is able to select things from the popup rather quickly. Since speed is a factor, i want to also add the ability to select items in a popup with the keyboard. Is it possible to assign item IDs belonging to a popup to keys and trigger them on keypress?

:bust_in_silhouette: Reply From: 1shevelov

I’m using this event handler in game scene, it checks if popup is_visible() and call things for various key presses:

func _input(event):
if event is InputEventKey and event.pressed:
	if menu_popup.is_visible():
		match event.scancode:
			KEY_Q, KEY_ESCAPE:
				menu_popup.hide()
            KEY_1:
                run_first_command()