Shared input betwen imgui and input actions #51
Replies: 2 comments 1 reply
-
Normally imgui-godot will consume input events before they reach an Unfortunately Godot doesn't seem to have any particularly elegant way of listening for mapped actions as events. I'll think about this more when I have time this weekend, but for now my best solution would be something like: private static readonly Godot.Collections.Array<StringName> _actions = InputMap.GetActions();
public static StringName? GetActionName(InputEvent evt)
{
if (evt.IsActionType())
{
foreach (StringName sn in _actions)
{
if (evt.IsAction(sn))
return sn;
}
}
return null;
}
public override void _UnhandledInput(InputEvent @event)
{
StringName? actionName = GetActionName(@event);
if (actionName != null)
{
GD.Print(actionName);
// handle actions here
}
} |
Beta Was this translation helpful? Give feedback.
-
Oh you can, that's exactly what the docs suggest, but it's directly examining the input data in a way that doesn't interact nicely with the rest of the event-driven input system. So there's no way I can un-set an action without some ugly hack that would probably cause other issues.
Yeah you should only have to worry about what the flags are on the current frame, that seems like a reasonable solution. |
Beta Was this translation helpful? Give feedback.
-
Currently, my Godot project's input map contains actions mapped to pressing various keys, like R, L etc. So, when I'm using ImGui.InputText and I start typing, whenever I press e.g. R it triggers the action as well. The ImGui C++ FAQ mentions how to handle this, but can this also somehow work with Godot? Because we don't exactly have direct access to input events.
I can see that when I'm hovering my mouse over any ImGui control, WantCaptureMouse is true, and when I'm typing things in ImGui controls then WantCaptureKeyboard is true. But I don't know if there's a way to tell Godot to stop reading actions with mouse and/or keyboard for a single frame if those flags are set. This might be a Godot question, but maybe there's some code in the backend and/or this project that might handle this?
Beta Was this translation helpful? Give feedback.
All reactions