TextureButton Hold

Godot Version

4.2.1 stable

I used Google translator and I apologize if anything is unclear.

Question

I need to make the button visually and programmatically hold when a key is hold and, in some cases, when the button is hold with the mouse.
All this should be responsible for moving the camera around the scene

I accomplished the first point using this code in TextureButton node and I also use the template to move CharacterBody2D “CharacterBody2D: Basic Movement”

extends TextureButton

func _ready():
	toggle_mode = false

func _process(delta):
	if Input.is_action_pressed("d"):
		toggle_mode = true
		button_pressed = true
	elif  Input.is_action_just_released("d"):
		toggle_mode = false
		button_pressed = false

But in the case of a mouse hold, I could only guess at code like this in CharacterBody2D node

func _on_left_button_down():
	Input.action_press("d")
func _on_left_button_up():
	Input.action_release("d")

buuuut this happens

(node settings and structure)

image

I thought about using touchscreen buttons, but they continue to be activated when the cursor is not on the button

and thanks in advance for help! :>

I thinki you are overcomplicating this.

My approach would be:

  1. Have the button be a TextureButton
  2. set the buttons default texture to your default texture
  3. set the buttons pressed texture to be that one
  4. set the buttons shortcut to a InputEventKey
  5. set the inputeventkey s scancode to the desired button code (you can find the codes here somewhere as “enum KeyList@GlobalScope — Godot Engine latest documentation)

Good Luck :wink: