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

windib returns locale dependent SDLK_ codes #95

Closed
SDLBugzilla opened this issue Feb 10, 2021 · 0 comments
Closed

windib returns locale dependent SDLK_ codes #95

SDLBugzilla opened this issue Feb 10, 2021 · 0 comments

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

These attachments are available in the static archive:

Reported in version: HG 1.2
Reported for operating system, platform: Windows (All), x86

Comments on the original bug report:

On 2006-03-14 13:37:19 +0000, John Popplewell wrote:

Running checkkeys.c with a Swedish keyboard layout produces inconsistent results when using the windib and directx backends. The key at the top-left of the keyboard, SDLK_BACKQUOTE is reported as being SDLK_BACKSLASH. This is caused by Windows returning a different VK_ code for this key when a Swedish keyboard layout is in use. This VK_ code clashes with the VK_ code returned for a different (physical) key on a UK keyboard.

So far, only reported on WinXP SP2.

Orignally reported by Tomas Jakobsson. In the referenced posting I use the term scancode, when I should have said SDLK_ code.

On 2006-03-14 15:49:25 +0000, John Popplewell wrote:

Created attachment 80
Always uses US keymap to create VK_ virtual key codes

To get your imaginations fired up, here's a hack that makes all keyboards look like a US keyboard so that it can return a language independent SDLK_ code.
Only tested on XP so far. Please tell me there is a better solution than this.

On 2006-03-15 06:17:02 +0000, John Popplewell wrote:

Comment on attachment 80
Always uses US keymap to create VK_ virtual key codes

Demonstrates the concept, but is badly broken.

On 2006-03-15 06:29:41 +0000, John Popplewell wrote:

Christian Walth has pointed this out to me: http://thread.gmane.org/gmane.comp.lib.sdl/24697

So I guess I'm exploring the possibility of making windib consistant with directx and into option 1.

Interestingly, whilst testing, I noticed that with the directx backend I get the same SDLK_ code for the #~ key (SDLK_BACKSLASH) and the | key on my UK keyboard, but this could be fixed by changing:

...
DIK_keymap[DIK_BACKSLASH] = SDLK_BACKSLASH;
DIK_keymap[DIK_OEM_102] = SDLK_BACKSLASH; <-- SDLK_LESS
...

On 2006-03-15 22:34:37 +0000, John Popplewell wrote:

Created attachment 83
Proposed patch for windib keyboard handling

Current bugs with windib keyboard support (testing with checkkeys.c):

  1. SDLK_ codes change with the keyboard mapping (dx doesn't)
  2. keypad SDLK_ codes change based on num lock (dx doesn't)
  3. return and keypad enter give the same SDLK_RETURN code (dx doesn't)
  4. on Win9x shift keys ignored in cvs, but used to give 'unknown scancode'

The behaviour of caps-lock and num-lock is documented, the behaviour of print-screen and pause (press/release sent once on keydown, nothing on keyup) is, I think, documented, and I haven't been able to do better this.

I've attached a patch for the numbered problems, but it has issues with the use of keyboard scancodes for the keypad and shift-keys (2&4).

It also fixes a cock-up (mine, I think) in the directx driver that causes two of the keys to have the same SDLK_ code.

Notes:

  1. is resolved by always using a US keyboard map to generate the SDLK_ code, but the MS function MapVirtualKeyEx() seems to be reliable only for 'printable' keys, so it's a bit messy.

  2. Uses scancodes, but could use VK_ codes instead, would still produce SDLK_ codes dependent on num-lock though. Required because MapVirtualKeyEx() doesn't handle the keypad properly.

  3. Should work fine everywhere.

  4. Uses scancodes, but would be reliable with a list of scancodes for each shift-key, as the VK_SHIFT code is reliable. Defaults to making both shift keys appear to be VK_LSHIFT.

On 2006-03-16 05:25:31 +0000, John Popplewell wrote:

Couple of other windib keyboard handling bugs:
5. shift keys don't roll-over, if you hold one down the other is ignored.
6. right-alt generates left-ctrl down, right-alt down/right-alt up, left-ctrl up.

I don't know how to fix these. Number 6 seems to be something to do with right-alt being used as a shift key on e.g. French keyboard.

On 2006-03-16 08:22:39 +0000, John Popplewell wrote:

Created attachment 84
Revised patch with scancodes mostly removed

Removed need for the majority of the scancodes. Just the ones for left/right shift on Win9x remain. Defaults to VK_LSHIFT if no match, and anyway, the left-right shift and ctrl keys aren't properly independent.

The code hurts the eyes less :) Tested on WinXP, Win2K, Win98SE.

On 2006-05-17 23:24:17 +0000, Ryan C. Gordon wrote:

This patch is now in Subversion (revision # 2477). Thanks!

--ryan.

On 2006-06-24 00:39:33 +0000, Sam Lantinga wrote:

By the way, this behavior will change in SDL 1.3 - the intended behavior is that the SDL keysyms reflect the key printed on the keyboard. This allows the end user to know what the 'z' key is, for example, without having to consult a picture of a US keyboard. Games which are indended to have the same layout in multiple locales should have different key maps for each keyboard layout.

sulix added a commit to sulix/sdl12-compat that referenced this issue Nov 5, 2021
SDL 1.2 seems to only account for (non-en_US) keyboard layouts on some
platforms and configurations. In particular, the KeySym may contain the
translated key, or may contain a "scancode" which is layout-independent.

In particular, on X11 the configured layout is used, but only (it seems)
if it is the only configured layout. (On systems where multiple layouts
are configured, the US layout is used regardless of the configured one.)
Similarly, the windib backend deliberately forces the US layout in order
to match the DirectX backend, which only provides scancodes.

Since this behaviour is very inconsistant between different
configurations, this patch provides a way of configuring which is used
at runtime:

If the SDL12COMPAT_USE_KEYBOARD_LAYOUT environment variable is set to a
nonzero value, sdl12compat will translate keyboard input according to
the current layout. This matches SDL 1.2 on X11 with only one configured
layout. Otherwise (the default), sdl12compat will use SDL2 scancodes for
keyboard input, essentially forcing all input to the US layout. This
matches SDL 1.2 on Windows, and on X11 with multiple configured layouts.

Regardless of the value of this environment variable, the 'unicode'
value will be affected by keyboard layout.

For discussion and more details see:
- sdl12compat issue libsdl-org#135: Non-US Keyboard layouts not supported
  libsdl-org#135
- sdl12compat PR libsdl-org#97: Use Scancodes instead of Keycodes
  libsdl-org#97
- SDL 1.2 issue libsdl-org#95: windib returns locale dependent SDLK_ codes
  libsdl-org/SDL-1.2#95
sulix added a commit to sulix/sdl12-compat that referenced this issue Nov 6, 2021
SDL 1.2 seems to only account for (non-en_US) keyboard layouts on some
platforms and configurations. In particular, the KeySym may contain the
translated key, or may contain a "scancode" which is layout-independent.

In particular, on X11 the configured layout is used, but only (it seems)
if it is the only configured layout. (On systems where multiple layouts
are configured, the US layout is used regardless of the configured one.)
Similarly, the windib backend deliberately forces the US layout in order
to match the DirectX backend, which only provides scancodes.

Since this behaviour is very inconsistant between different
configurations, this patch provides a way of configuring which is used
at runtime:

If the SDL12COMPAT_USE_KEYBOARD_LAYOUT environment variable is set to a
nonzero value, sdl12compat will translate keyboard input according to
the current layout. This matches SDL 1.2 on X11 with only one configured
layout. Otherwise (the default), sdl12compat will use SDL2 scancodes for
keyboard input, essentially forcing all input to the US layout. This
matches SDL 1.2 on Windows, and on X11 with multiple configured layouts.

Regardless of the value of this environment variable, the 'unicode'
value will be affected by keyboard layout.

For discussion and more details see:
- sdl12compat issue libsdl-org#135: Non-US Keyboard layouts not supported
  libsdl-org#135
- sdl12compat PR libsdl-org#97: Use Scancodes instead of Keycodes
  libsdl-org#97
- SDL 1.2 issue libsdl-org#95: windib returns locale dependent SDLK_ codes
  libsdl-org/SDL-1.2#95
slouken pushed a commit to libsdl-org/sdl12-compat that referenced this issue Nov 6, 2021
SDL 1.2 seems to only account for (non-en_US) keyboard layouts on some
platforms and configurations. In particular, the KeySym may contain the
translated key, or may contain a "scancode" which is layout-independent.

In particular, on X11 the configured layout is used, but only (it seems)
if it is the only configured layout. (On systems where multiple layouts
are configured, the US layout is used regardless of the configured one.)
Similarly, the windib backend deliberately forces the US layout in order
to match the DirectX backend, which only provides scancodes.

Since this behaviour is very inconsistant between different
configurations, this patch provides a way of configuring which is used
at runtime:

If the SDL12COMPAT_USE_KEYBOARD_LAYOUT environment variable is set to a
nonzero value, sdl12compat will translate keyboard input according to
the current layout. This matches SDL 1.2 on X11 with only one configured
layout. Otherwise (the default), sdl12compat will use SDL2 scancodes for
keyboard input, essentially forcing all input to the US layout. This
matches SDL 1.2 on Windows, and on X11 with multiple configured layouts.

Regardless of the value of this environment variable, the 'unicode'
value will be affected by keyboard layout.

For discussion and more details see:
- sdl12compat issue #135: Non-US Keyboard layouts not supported
  #135
- sdl12compat PR #97: Use Scancodes instead of Keycodes
  #97
- SDL 1.2 issue #95: windib returns locale dependent SDLK_ codes
  libsdl-org/SDL-1.2#95
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant