How to make mouse actions repeat _input call

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

I need to use _input, but I also need a mouse action that behaves like a key, in the sense that while pressed it calls _input continuously. It seems impossible. Any suggestions?

:bust_in_silhouette: Reply From: literalcitrus

You could create a flag that is set to true on the mouse pressed action, and false on the mouse released action, and then use _process() or some other technique to continuously fire off whatever you need to do.

I would hardly be using _input if I did this. No, there’s a reason why to use _input instead of _process and doing this gimmick is the same as using only _process

mateusak | 2018-02-14 04:01

There is no way to check whether a mouse button is pressed other than periodically polling it, or keeping track of its state externally. The mouse just doesn’t fire input events the same way keys do. Keys only repeatedly fire input events because that’s the behaviour of a key that is held down - after a short period of the key being held the OS starts firing off more key presses which Godot detects. You can test this yourself.

Looks like it’s either this gimmick or you’re using only _process().

literalcitrus | 2018-02-14 04:58

I setup a on_mouse_pressed(just_begun, released) signal and on the firearm a timer with the corresponding fire rate, which would call a function as long as mouse was pressed. Like this:

func _ready():
	Player.connect("on_mouse_pressed", self, "attack")
	Timer.connect("timeout", self, "attack", [false, false])

func attack(begun, released):
	if released:
		Timer.stop()
		return
		
	Timer.start()

This allows me to achieve any fire rate, i.e 120, without using the fps depending _process or the limited at 60 _physics_process.

mateusak | 2018-02-14 12:05