You can use polling to see if the mouse button is being held down.
func _ready():
set_process(true)
func _process(delta):
if Input.is_mouse_button_pressed(1): # Left mouse button.
print('Left mouse button pressed. ', get_viewport().get_mouse_position())
Otherwise, you can set a variable, for example mouse_button_pressed
, to true
or false
in the _input
function when a mouse button is pressed or released and then check it in the _process
function:
func _input(event):
if event is InputEventMouseButton:
if event.is_pressed(): # Mouse button down.
mouse_button_pressed = true
elif not event.is_pressed(): # Mouse button released.
mouse_button_pressed = false
func _process(delta):
if mouse_button_pressed:
print('Left mouse button pressed. ', get_viewport().get_mouse_position())