f2e-spec icon indicating copy to clipboard operation
f2e-spec copied to clipboard

Keyboard layout issues: assumes stock US layout or similar, as it uses scancodes

Open mirabilos opened this issue 6 years ago • 6 comments

Do you want to request a feature or report a bug?

Bug

What did you do?

I’m running with a custom keyboard layout (mapping graphics) which, while US-based, assigns more or different meaning to the keys (e.g. adds a Compose key and makes the Caps Lock key into a normal input), but — more importantly for this bug — swaps Esc with the ``` key.

I know people using the DVORAK or Neo2 keyboard layouts, which have the P key on a different scancode from US.

What did you expect to see?

I’d like to be able to use Performous without needing to temporarily switch back to vanilla US layout (setxkbmap us), and I’m sure others also want to.

What did you see instead?

I cannot exit the song list: when I press Esc (on the key left to the 1, <TLDE> in xkb), it gets (via sdl2test.c)…

SDL_KEYDOWN: Keycode: Escape (27) Scancode: ` (53)
SDL_KEYUP: Keycode: Escape (27) Scancode: ` (53)

… which is interpreted by scancode as hitting , and when I press (on the Esc key, <ESC> in xkb), it gets…

SDL_KEYDOWN: Keycode: ` (96) Scancode: Escape (41)
SDL_TEXTINPUT: `
SDL_KEYUP: Keycode: ` (96) Scancode: Escape (41)

… which works everywhere except in the song browser, because it’s interpreted as text input there.

The scancode approach is problematic because SDL2 does some of its own mapping, too…

Looking at game/controllers-keyboard.cc and game/screen_songs.cc, Performous uses scancodes throughout, which are hard-bound to a physical keyboard layout, e.g. they assume that the scancode P is always on the <AD10> xkb key, which is untrue for DVORAK and Neo2, among others.

From the SDL2 documentation you will wish to be using keycodes (e.g. SDLK_ESCAPE and SDLK_p) throughout your entire event handling; SDL is nice enough to assign faux keycodes like SDLK_RIGHT to things like cursor keys which would otherwise not have a text equivalent. Using keycodes also takes care of layouts where something that’s unshifted on US is shifted (most famous example is French in which the number digits are shifted and the &, ", etc. are unshifted).

Output of performous --version: (What version of Performous are you using?)

Performous 1.1+

git 9928c27

What is your environment & configuration (arguments, platform, ...)?

Debian GNU/Linux sid/amd64

If applicable, please paste the log output in DEBUG level (--logLevel=DEBUG switch)

not applicable, but you might wish to fix your bug submission template ☻

mirabilos avatar Sep 30 '19 15:09 mirabilos

The scancodes in https://github.com/performous/performous/blob/master/game/controllers-keyboard.cc#L65 probably should be something else. Would you care to investigate and send a pull request with the necessary changes? SDL2 documentation would be a place to start.

Tronic avatar Sep 30 '19 16:09 Tronic

I had to deal with similar shit back when I was working on a Firefox extension and it was a nightmare. Your report is very thorough, so it shouldn't be very hard to fix but all my coding energy lately has been going into a a zillion ignored PRs upstream in MXE (ultimate goal being able to produce trustworthy windows builds again)

Sent with GitHawk

Lord-Kamina avatar Sep 30 '19 16:09 Lord-Kamina

L. Kärkkäinen dixit:

The scancodes in https://github.com/performous/performous/blob/master/game/controllers-keyboard.cc#L65 probably should be something else. Would you care to investigate and send a pull request with the necessary changes? SDL2 documentation would be a place to start.

Sure, I can have a shot at converting it. Thanks, I don’t have much spare time (working in too many OSS projects) and didn’t want to start something which upstream isn’t interested in merging, but since you ask…

bye, //mirabilos

Solange man keine schmutzigen Tricks macht, und ich meine wirklich schmutzige Tricks, wie bei einer doppelt verketteten Liste beide Pointer XORen und in nur einem Word speichern, funktioniert Boehm ganz hervorragend. -- Andreas Bogk über boehm-gc in d.a.s.r

mirabilos avatar Sep 30 '19 17:09 mirabilos

Isn't it frustrating when more effort goes into arguing why your pull requests should be merged than actually fixing things? I can guarantee that any fix that doesn't break QWERTY/QWERTZ/AZERTY layouts will get merged promptly (and as a Colemak user I'll send you my love if that also gets fixed!).

Tronic avatar Oct 01 '19 05:10 Tronic

However, I see I pointed you probably at the wrong point in code. Scancodes are used for letters precisely so that the guitar keys stay in same locations, but you want to move function keys to different locations as per OS keymap. In any case, I'm sure you can sort it out, if SDL2 just gives the necessary tools.

Tronic avatar Oct 01 '19 05:10 Tronic

Isn't it frustrating when more effort goes into arguing why your pull requests should be merged than actually fixing things? I can guarantee that any fix that doesn't break QWERTY/QWERTZ/AZERTY layouts will get merged promptly (and as a Colemak user I'll send you my love if that also gets fixed!).

That it will (we're not dead yet haha ñ) and god yes. MXE is a great project but it has some really crazy inertia on some things.

If I cannot get them to merge changes I'll probably just push them to performous' fork but I'd still rather see things fixed upstream.

Lord-Kamina avatar Oct 01 '19 07:10 Lord-Kamina