Swapped keyboard keys not always recognized

Bug #1618557 reported by Steven De Herdt
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
widelands
Fix Released
Undecided
Unassigned

Bug Description

Minor inconvenience: I have my left ctrl and caps_lock switched, but the current dev version doesn't recognize that when deleting roads or presetting locations. When I got the clue that I have to press the real ctrl for that, I was a bit surprised that text input does honour my peculiar caps_lock key location.
I would guess that it works like this since SDL2 - no more than a guess though. Can WL (reasonably) be made to follow my keyboard settings like it used to?

Related branches

Revision history for this message
GunChleoc (gunchleoc) wrote :

We went for the physical key in some cases:

   if (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL))

and for the semantic key in others:

   if (code.mod & (KMOD_LCTRL | KMOD_RCTRL))

I agree that the behavior needs to be consistent, and I vote for the second option.

tags: added: lowhangingfruit ui
Changed in widelands:
status: New → Triaged
GunChleoc (gunchleoc)
Changed in widelands:
milestone: none → build20-rc1
Revision history for this message
Steven De Herdt (stdh) wrote :

This inconvenience became a bit too big for me and I dug around some, with resulting patch attached. In most cases I replaced (get_key_state(SDL_SCANCODE_LCTRL) || get_key_state(SDL_SCANCODE_RCTRL) with (SDL_GetModState() & KMOD_CTRL) [note: KMOD_CTRL==KMOD_LCTRL|KMOD_RCTRL], except in one place where the keysym was available. Direct invocation of the SDL function is perhaps not the cleanest design, it feels strange handling hardware while deciding what flags/buildings to bulldoze. I'm no expert programmer/designer, but some comments (e.g. ui_basic/window.cc line 367, identical comment repeated a few times) seem to agree it's fishy. I suppose doing it cleanly would require some substantial refactoring...

(This patch also removes a bitshift of booleans (in actionconfirm.cc), did that serve any purpose besides being confusing?)

There's some "get_key_state(SDL_SCANCODE_*)" I didn't touch: some involving arrow keys and/or keypad (interactive_base.cc and game_message_menu.cc) and some involving Mac (wlapplication.cc).

I manually tested this patch and it seems to work.

P.S. One trigger for working on this is that "ctrl-+" does not actually zoom in. The SDL wiki says SDLK_PLUS is a virtual key, so we seem to need something else. But "ctrl-shift-=' is maybe not universal (works for Belgian AZERTY though)... Also "ctrl-0" in the editor resets zoom and sets toolsize to 10 at the same time.

P.P.S. This got me curious, how are shortcuts (like 'c' for census) supposed to work for non-Latin keyboard layouts? Do their users just habitually switch to QWERTY for gaming or so?

Revision history for this message
GunChleoc (gunchleoc) wrote :

Thanks for the patch - I have created a branch.

The bitshift is a typo - on a German keyboard, when you press < + Alt Gr, you get |. So, this was supposed to be ||.

I will fix the ctrl-0 issue in the attached branch.

Actually, I don't know how the hotkeys work for non-Latin keyboards. It's worth looking into.

Revision history for this message
GunChleoc (gunchleoc) wrote :
GunChleoc (gunchleoc)
Changed in widelands:
status: Triaged → Fix Committed
Revision history for this message
Steven De Herdt (stdh) wrote :

Thanks for getting this in.

About the bitshift: I never thought of C++ as a language so robust that you could mistype an operator and still have it working. :) (Well, at least with the left control key.)

I've been looking a bit into "ctrl-+". As I found out, this just works on a German QWERTZ layout. For other layouts, where you might need shift to produce "+", it's not so easy. If we want to make the keyboard shortcut logic work universally we seem to have three choices:
1. use the 'unicode' field of a keyboard event, which is obsolete in SDL2;
2. use TextInput events;
3. translate the symbol '+' to the right Keycode and Keymod for the current layout ourselves, without support by SDL.
Am I missing any more attractive ways to solve this? Good to know: this problem also occurs for other shortcuts which require shift, like the number keys in AZERTY.

Revision history for this message
GunChleoc (gunchleoc) wrote :

Fixed in build20-rc1

Changed in widelands:
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.