mouse click action with/without control key ?

Godot Version 4.4.1

Question

I created 2 actions, one bound to left-mouse-click, the other to left-mouse-click+control-key.
But it seems that the first action is also fired when the control key is pressed.
Is there a way to exclude this case in the project/input map ? Or, in GD script, should I first check the left-mouse-click+control-key action, and then the left-mouse-click action if the first one is not triggered ?
(this solution does not seem appropriate, because it supposes that the code “knows” which event is bound to which action…)

Hi,

Input actions do not know about each other, as far as I’m aware of. From a human perspective, it seems logical to ignore a simple click if there’s another similar action with the Ctrl modifier added, but from code perspective, I don’t think it does.

You can definitely do that, yes. Checking the most specific action first, then checking the least specific will work perfectly fine. I suppose you already know how to write such a code, but in case someone else reads that thread and needs a snippet:

if Input.is_action_just_pressed("action_ctrl"):
    print("Action (with ctrl)")
elif Input.is_action_just_pressed("action"):
    print("Action (no ctrl)")
1 Like

Interesting. I just tried out myself, and seems like Godot ignores the modifier keys. If I set an action as Ctrl+Left mouse, it triggers on only left mouse. If I hold Ctrl while left mousing, I get two of the events. Same with something like Shift+a.

The input map tells me this action is tied to Shift+a, yet it triggers on only a. Seems like a bug to me. So basically, there’s no way to use modifier keys in Godot?

Edit: is_action() reports the action falsely (in my opinion), but is_action_pressed() doesn’t.

1 Like

Have a look at the exact_match parameter of Input.is_action_just_pressed(action: StringName, exact_match: bool = false).
You can specify, if you want to match also for modifiers.

2 Likes

Thanks @sixrobin for your help.
But imagine that I want to let the user choose his mouse bindings, allowing him to exchange both actions click events, using ctrl-click on action A and simple-click on action B. Then this code won’t work…

Thanks to @Sauermann who has the perfect solution. I just forgot to read the optional parameter of is_action_just_pressed :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.