Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Input.is_action_pressed does not report the correct action when releasing a modifier key #99757

Open
doctor-g opened this issue Nov 27, 2024 · 0 comments

Comments

@doctor-g
Copy link

Tested versions

  • Reproducible in 4.3.stable.official

System information

Godot v4.3.stable - Ubuntu 24.04.1 LTS 24.04 - X11 - Vulkan (Forward+) - dedicated NVIDIA GeForce GTX 1070 (nvidia; 535.183.01) - Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz (12 Threads)

Issue description

In the _process or _physics_process functions, actions are not being properly recognized by Input.is_action_pressed when a modifier key is released, even when exact_match is true.

Consider two keyboard actions, "walk" and "run", which are both bound to the right arrow, but the latter of which uses the Shift key as a modifier. Pressing shift-right will be recognized as "run," but upon releasing the modifier key, the action continues to be recognized as "run" rather than being interpreted as "walk".

That is, given code like this:

func _process(_delta: float) -> void:
	if Input.is_action_pressed("run", true):
		_process_label.text = "Run"
	elif Input.is_action_pressed("walk", true):
		_process_label.text = "Walk"
	else:
		_process_label.text = "Idle"

if I give the "run" input, then release the shift key, it continues to report the "run" action as matching even though it should instead be the "walk" action.

Strangely, this happens only if the modified action is tested first. The following code works as expected, where "walk" is the unmodified action and "run" is the modified one:

func _process(_delta: float) -> void:
	if Input.is_action_pressed("walk", true):
		_process_label.text = "Walk"
	elif Input.is_action_pressed("run", true):
		_process_label.text = "Run"
	else:
		_process_label.text = "Idle"

One would expect these two functions to have the same behavior, but they don't.

Note that the _input function and its InputEvent.is_action work as expected, correctly distinguishing between the two states. That is, when running, if releasing the shift key, the input is then recognized as "walk".

Steps to reproduce

  • Create two keyboard input actions that are different only in that one takes a modifier key (e.g. shift)
  • In the _process function, use Input.is_action_pressed to monitor the state of the input.
  • See that the unmodified action is recognized, then pressing the modifier makes the modified action recognized, but releasing the modifier does not revert back to recognizing the unmodified action

Minimal reproduction project (MRP)

When running the example,

  • press right to recognize the "walk" action
  • then press shift also to recognize the "run" action
  • then release shift, keeping right held down, and see that it stays "run" rather than reverting to "walk"

The example also illustrates how this behavior is different from the _input function, which correctly distinguishes between "run" and "walk" using the is_action function.

example.zip

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant