0 votes

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.

in Engine by (39 points)

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?

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.

1 Answer

0 votes

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.

by (27,966 points)
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 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 webmaster@godotengine.org with your username.