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

Inconsistent output of InputEventKey.as_text() with Czech keyboard layout on Linux #54797

Closed
mnn opened this issue Nov 9, 2021 · 7 comments · Fixed by #70052
Closed

Inconsistent output of InputEventKey.as_text() with Czech keyboard layout on Linux #54797

mnn opened this issue Nov 9, 2021 · 7 comments · Fixed by #70052

Comments

@mnn
Copy link

mnn commented Nov 9, 2021

Godot version

3.4.stable

System information

Linux (Manjaro)

Issue description

It mixes "key from keyboard layout" with "physical key" (or maybe US keyboard layout?).

This is an output of me pressing top number keys from 1 to 0 (from left to right):

<<Plus>> 43 49
<<2>> 50 50
<<3>> 51 51
<<4>> 52 52
<<5>> 53 53
<<6>> 54 54
<<ý>> 253 55
<<á>> 225 56
<<í>> 237 57
<<é>> 233 48

Either everything should be a number (US keyboard layout interpretation) 1234567890 or it should be +ěščřžýáíé (CS keyboard layout). Now it's somehow mixed together.

Steps to reproduce

Select a non-US keyboard layout (e.g. Czech) and call as_text on InputEventKey. Try pressing keys which are different to US layout.

Minimal reproduction project

func _input(event: InputEvent) -> void:
	if event is InputEventKey && event.is_pressed():
		print("<<%s>> %s %s" % [event.as_text(), event.scancode, event.physical_scancode])
@akien-mga akien-mga changed the title Inconsistent output of InputEventKey.as_text() Inconsistent output of InputEventKey.as_text() with Czech keyboard layout on Linux Nov 9, 2021
@akien-mga
Copy link
Member

akien-mga commented Nov 9, 2021

Works fine with French keyboard layout on Linux:

<<Ampersand>> 38 49
<<é>> 233 50
<<QuoteDbl>> 34 51
<<Apostrophe>> 39 52
<<ParenLeft>> 40 53
<<Minus>> 45 54
<<è>> 232 55
<<UnderScore>> 95 56
<<ç>> 231 57
<<à>> 224 48
<<ParenRight>> 41 45
<<Equal>> 61 61

I can reproduce the issue with Czech keyboard layout (setxkbmap cz), I guess it does something uncommon with the 2-6 key overrides. CC @bruvzg

The xkb mapping looks like this (/usr/share/X11/xkb/symbols/cz):

    include "latin"
    name[Group1]= "Czech";

    key <TLDE>  { [ semicolon, dead_abovering,    grave,   asciitilde ] };
    key <AE01>  { [      plus,          1,       exclam,   dead_tilde ] };
    key <AE02>  { [    ecaron,          2,           at,   dead_caron ] };
    key <AE03>  { [    scaron,          3,   numbersign, dead_circumflex ] };
    key <AE04>  { [    ccaron,          4,       dollar,   dead_breve ] };
    key <AE05>  { [    rcaron,          5,      percent, dead_abovering]};
    key <AE06>  { [    zcaron,          6,  asciicircum,  dead_ogonek ] };
    key <AE07>  { [    yacute,          7,    ampersand,   dead_grave ] };
    key <AE08>  { [    aacute,          8,     asterisk, dead_abovedot] };
    key <AE09>  { [    iacute,          9,    braceleft,   dead_acute ] };
    key <AE10>  { [    eacute,          0,   braceright, dead_doubleacute ] };
    key <AE11>  { [     equal,    percent,     NoSymbol, dead_diaeresis]};
    key <AE12>  { [dead_acute, dead_caron,  dead_macron, dead_cedilla ] };

@mnn
Copy link
Author

mnn commented Nov 9, 2021

I also noticed that for a key ´ (two keys to the right from the number 0 on top row) I am getting <<Unknown>> 33554431 33554431 which would be ok, but it happens only every second key press which might be an issue. It looks like every first press of this key is ignored, it behaves like when writing text - for example you press a ´ key and then an a key to get a á symbol (two presses of ´ produce that standalone symbol).

@akien-mga
Copy link
Member

I also noticed that for a key ´ (two keys to the right from the number 0 on top row) I am getting <<Unknown>> 33554431 33554431 which would be ok, but it happens only every second key press which might be an issue. It looks like every first press of this key is ignored, it behaves like when writing text - for example you press a ´ key and then an a key to get a á symbol.

That's normal, it's a dead key, so the first keypress holds the diacritic for you to put on a letter. ´ + E should give you "é".

@mnn
Copy link
Author

mnn commented Nov 9, 2021

So it's not possible to use dead keys for key bindings at all? Or would I have to use some other input event? I thought scancodes are related to physical keys, not their interpretation in keyboard layout.

@Kersoph
Copy link

Kersoph commented Dec 5, 2022

As a hint as Czech and French keyboards are mentioned:
Scancodes for CH-Keyboards are not fully working as well with .as_text()

E.g.:

ö is translated with "Apostrophe Key"
ä is translated with "BackSlash Key"
ü is translated with "Semicolon Key"
also not working are for example éà£!è$¨^'§

Using the Unicode field and casting it to a letter works. Probably the reason why LineEdit works perfect. I'm posting here because I'm unsure if it is connected and if it's may be already solved for the Unicode case as well for the Czech layout? Then it may has the same cause.
The problem arises when you do not have the Unicode uint e.g., when you want to remap default keys in a game.

@akien-mga
Copy link
Member

CC @bruvzg

@bruvzg
Copy link
Member

bruvzg commented Dec 5, 2022

ö is translated with "Apostrophe Key"
ä is translated with "BackSlash Key"
ü is translated with "Semicolon Key"

There's no such thing as scan code for ö, so this is full expected, use Unicode value for this.

See Microsoft Keyboard Scan Code Specification for the list of standard PS/2 scan codes (all keyboard still use the same set).

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

Successfully merging a pull request may close this issue.

5 participants