godot icon indicating copy to clipboard operation
godot copied to clipboard

InputEventAction remains pressed

Open viraelin opened this issue 1 year ago • 1 comments

Tested versions

  • Reproducible in v4.3.stable.official [77dcf97d8], not in v4.2.2.stable.official [15073afe3]

System information

Godot v4.3.stable - Arch Linux

Issue description

InputEventAction with pressed set to true when sent through Input.parse_input_event() continues emitting as pressed until that event_index real key/button is released (or pressed then released if it was not pressed) or until window focus is lost.

This was not the case in 4.2.2, is it intended for action to remain pressed when sending fake InputEventAction?

If it is intentional, is sending another event such as the code below then the intended solution? By the documentation for InputEventAction.event_index, it reads as if it is not:

"The real event index in action this event corresponds to (from events defined for this action in the InputMap). If -1, a unique ID will be used and actions pressed with this ID will need to be released with another InputEventAction."

if event.is_action_pressed(&"ui_up"):
	var ev: = InputEventAction.new()
	ev.action = &"ui_down"
	ev.pressed = true
	ev.event_index = 0
	Input.parse_input_event(ev)
	var ev2: = InputEventAction.new()
	ev2.action = &"ui_down"
	ev2.pressed = false
	ev2.event_index = 0
	Input.parse_input_event(ev2)

Steps to reproduce

  1. download MRP/open project/run project, for 4.3
  2. press and release ui_up key (up arrow)
  3. one InputEventAction should be printed to console as well as continuous stream of true until focus is lost or ui_down is pressed and released

If testing in 4.2.2, the ev.event_index = 0 line will need to be commented.

Minimal reproduction project (MRP)

43_input_event_action.zip

viraelin avatar Aug 17 '24 03:08 viraelin

Actions are now tracked per event id (after #84685 and #84943) to improve their reliability. This means that to release an action you need to release all its assigned events.

KoBeWi avatar Aug 17 '24 10:08 KoBeWi

The following appears to solve the issue for my use case.

static func press_action(action: StringName) -> void:
	var event_press: = InputEventAction.new()
	event_press.action = action
	event_press.pressed = true
	event_press.event_index = -1
	Input.parse_input_event(event_press)

	var event_release: = InputEventAction.new()
	event_release.action = action
	event_release.pressed = false
	event_release.event_index = -1
	Input.parse_input_event(event_release)

viraelin avatar Aug 17 '24 20:08 viraelin