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

Regression: InputEvent.is_action_pressed is true for Control+<key> even if only <key> is pressed when not using exact_match #57943

Closed
EIREXE opened this issue Feb 10, 2022 · 14 comments · Fixed by #59343

Comments

@EIREXE
Copy link
Contributor

EIREXE commented Feb 10, 2022

Godot version

3.x c7f09c1

System information

Arch Linux

Issue description

When assigning a key with a modifier to an input event (such as Control+D) it works with is_action_pressed unless exact_match is specified, I believe this is a regression as this was never the behavior before. I can confirm it didn't happen in b423dc0

Steps to reproduce

Create a new input event with a modifier such as Control+d and try checking for it in an input event using InputEvent.is_action_pressed

Minimal reproduction project

mrpok.zip

@Calinou
Copy link
Member

Calinou commented Feb 10, 2022

@EIREXE Please upload a minimal reproduction project to make this easier to troubleshoot.

@akien-mga
Copy link
Member

Likely related to #54174, CC @nathanfranke.

@nathanfranke
Copy link
Contributor

nathanfranke commented Feb 10, 2022

Cannot reproduce in 118494d

Input action named test with Control+D set

Both Press 1 and Press 2 (after I press Control+D) are printed.

func _ready():
	var key := InputEventKey.new()
	key.scancode = KEY_D
	key.control = true
	key.pressed = true
	if key.is_action_pressed("test", false, true):
		print("Press 1")

func _input(event):
	if event.is_action_pressed("test", false, true):
		print("Press 2")

@EIREXE
Copy link
Contributor Author

EIREXE commented Feb 10, 2022

@nathanfranke is exact_match needed now? It used to not be needed I believe the behavior has changed from before
I also tested this on 3.4.2 stable and the behavior is correct there

@EIREXE
Copy link
Contributor Author

EIREXE commented Feb 10, 2022

MRP has been uploaded, it's not too complicated though

@nathanfranke
Copy link
Contributor

With exact_match = true, Control+D works
With exact_match = false, D and Control+D work

Is this what you get too?

@EIREXE
Copy link
Contributor Author

EIREXE commented Feb 11, 2022

With exact_match = true, Control+D works With exact_match = false, D and Control+D work

Is this what you get too?

Yep, that is what I get, in 3.4.2 only control d works

@nathanfranke
Copy link
Contributor

I consider that expected behavior, but maybe we can get other input

@akien-mga
Copy link
Member

Well if it's breaking compat it might be problematic. Maybe this should default to exact_match = true?

@EIREXE
Copy link
Contributor Author

EIREXE commented Feb 12, 2022

Well if it's breaking compat it might be problematic. Maybe this should default to exact_match = true?

to me that sounds like a good way to do it

@nathanfranke
Copy link
Contributor

nathanfranke commented Feb 12, 2022

I would argue that would break more compatibility, since with exact_match = true, an input map action of D would not match Control+D by default.

Right now it behaves as the documentation describes:

If exact_match is false, it ignores the input modifiers for InputEventKey and InputEventMouseButton events

@akien-mga
Copy link
Member

I would argue that would break more compatibility, since with exact_match = true, an input map action of D would not match Control+D by default.

Well that's how it behaves in 3.4, no?

func _input(event):
	if event.is_action_pressed("action_d"):
		print("d pressed")
	if event.is_action_pressed("action_ctrl_d"):
		print("ctrl+d pressed")

Pressing D prints d pressed. Pressing Ctrl+D prints d pressed and ctrl+d pressed.

@madmiraal
Copy link
Contributor

I confirm that there has been a change in behaviour in 88e2c51 (but no change in behaviour between 3.4 and 3.4.3):

In 88e2c51 with Action: Ctrl+D:

Exact match: False (Default) True
Press D: Yes No
Press Ctrl+D: Yes Yes

In 3.4.3 with Action: Ctrl+D:

Exact match: False (Default) True
Press D: No No
Press Ctrl+D: Yes Yes

Pressing D now returns positive for an Action with Ctrl+D whereas before it didn't. Previously the parameter exact only affected actions without modifiers. Setting exact to true prevented pressing Ctrl+D from returning positive for an action: D.

In 88e2c51 with Action: D:

Exact match: False (Default) True
Press D: Yes Yes
Press Ctrl+D: Yes No

In 3.4.3 with Action: D:

Exact match: False (Default) True
Press D: Yes Yes
Press Ctrl+D: Yes No

@EricEzaM
Copy link
Contributor

EricEzaM commented Mar 20, 2022

I would argue that would break more compatibility, since with exact_match = true, an input map action of D would not match Control+D by default.

Right now it behaves as the documentation describes:

If exact_match is false, it ignores the input modifiers for InputEventKey and InputEventMouseButton events

@nathanfranke Sorry, thats probably my bad in the way that I wrote the feature but did not write the doco for it. Doco PR: #51064 Implementation PR: #44355.

It would probably be more correct to say

If exact_match is false, it ignores additional input modifiers for InputEventKey... [etc]

If the action is Ctrl+D, we want Ctrl+D to be matched at a minimum. If additional modifiers are pressed, e.g. Ctrl+Shift+D, then exact=false allows this, whereas exact=true disallows it. I apologise for any confusion caused.

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

Successfully merging a pull request may close this issue.

6 participants