Godot emitting input event signals

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

Hi, so I am trying to make it possible to when I hit “enter” on a particular item, it does the same thing as it would do if I clicked on that item.

I tried to do something like this

get_node("area2dnode").emit_signal("input_event") 

but unfortunately that didn’t work… any suggestions on how I’d do this?

If you need additional information I’d be happy to give it, but I’m not sure what else would be useful here.

What would be a situation where you would have this behavior? Would the user have the choice of either using a mouse, or using the arrow keys on the keyboard, to select the item?

Ertain | 2020-09-10 23:30

Yes. I’d like full freedom for the user to use what they feel more comfortable with. Its a turn based RPG and a user can either click Attack then click on an enemy, or select attack with the keyboard and selecting an enemy with the keyboard as well.

I actually ended up writing a function that both the enter button and the area click signal both call. This seems to work.

scarletred012 | 2020-09-11 00:01

:bust_in_silhouette: Reply From: Zylann

I would advise against calling obj.emit_signal on another object like that. Signals are emitted from objects themselves, not a third-party.

If you know how to either detect the click or the enter key on your area, one way would be to attach a script on it to customize it.
That script would detect both clicks and enter key, and emit a custom activated signal when it happens.
Then, you’ll be able to connect behavior to that signal, without having to mess with what could have triggered it.

Having your game logic directly do that without intermediary signal would work too though, as long as only one scripts listens to it.