godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
91k stars 21.17k forks source link

Dead keys trigger two times every other press when used as input on Windows #94517

Open Giganzo opened 3 months ago

Giganzo commented 3 months ago

Tested versions

Godot v4.3.beta3

System information

Godot v4.3.beta3 - Windows 10.0.19045

Issue description

When using a keyboard layout with dead keys (like United States-International) and you use it as input it trigger the action two times every other press. This would cause problems if say you have set an input to a physical key that corresponds to a dead key on the users keyboard layout. Or if a user want to use a key that happens to be a dead key, for what ever reason that could be.

This is also true when used for shortcuts in the editor

Tested this in some other programs, and Inkscape had same behavior as Godot. Gimp was one of the programs that worked. This problem doesn't seem to happen on a Debian system I tested on.

Steps to reproduce

Set an input action to physical key QuoteLeft on a US keyboard layout Add a function that prints or rotate something when this input is pressed Switch to United States-International layout

or in the editor

Set "zoom in" to physical key QuoteLeft set zoom to 25% With the US layout it will go 35.4% > 50% set it to 25% again Switch to United States-International layout Now it goes 35.4% > 70.7%

Minimal reproduction project (MRP)

deadkeys.zip

jitspoe commented 3 months ago

So today I learned that deadkeys exist. 😅

I got a bug report on my developer console about the ^ character showing up after opening the console using the German keyboard layout: https://github.com/jitspoe/godot-console/issues/13

So the code is like this:

func _input(event : InputEvent) -> void:
    if (event is InputEventKey):
        if (event.get_physical_keycode_with_modifiers() == KEY_QUOTELEFT): # ~ key.
            if (event.pressed):
                toggle_console()
            get_tree().get_root().set_input_as_handled()

And the behavior on German keyboards is that the first press of the key on the key to the left of the number row (~ on QWERTY keyboards, ^ on German), does nothing. The second press opens the console. Have to press it twice to close the console as well. When typing text into the console, it prepends ^ to it.

Not sure if this is a Godot input bug or something I need to explicitly work around. Behavior seems unexpected, though. I would expect the first ^ press to register, even if it doesn't display text.

Calinou commented 3 months ago

cc @bruvzg