I have an ItemList that allows Multi Select. However, I want to have the user select multiple items without a keyboard.
I would like to toggle a button and as long as it is toggled, it simulates a Ctrl or Shift key being held down. This way the user can just click on multiple items.
Is this possible?

Yes, you can generate (or spoof) actions with the Input class. Here is an example:

var a = InputEventAction.new()
a.action = "ui_cancel"
a.pressed = true
Input.parse_input_event(a)

You would just need to create a new action in the Input Map settings and bind it to Control and Shift, then give the action a name and replace the "ui_cancel" in the above code with your new action, such as "select_multiple".

Cyberreality, thank you for the response. Funny, I had actually tried nearly this exact same code, and when it didn't work, I posted my question. This code doesn't hold the Ctrl key down for me.

Not sure, but the UI may be reading modifier keys directly and not through the input action system. In which case it would work for purely code events (like is_action_pressed()) but not for lists or menus. I would hope there is some way to do it, maybe I can investigate later tonight.

I my goodness. I figured it out! It was so easy.
I created a button that can be toggled. In the _Input(InputEvent @event) function I check under the mousebutton event whether the button is toggled(pressed). If so... change the "Control" property of the event to true:

public override void _Input(InputEvent @event) { if (@event is InputEventMouseButton mbe) { if(btnMultiSelect.Pressed) { mbe.Control = true; } } }

That's it! Now the click registers with the ItemList as is if the Control button was held down. The same thing can be done for Alt and Shift. Hopefully this will help others who come across this problem.

Interesting. I did not know you could do that. Thanks for posting the solution.

9 months later