ppy / osu-framework

A game framework written with osu! in mind.
MIT License
1.66k stars 419 forks source link

Custom backspace buttons on windows language don't work. #1463

Open columna1 opened 6 years ago

columna1 commented 6 years ago

#2216 posted here as it's a framework issue.

I use a keyboard layout called Colemak which maps the caps lock button to backspace. This backspace doesn't work for me using the windows language feature to switch layouts.

I haven't tried with other buttons mapped to backspace, just the caps lock button To reproduce: either create a new layout with msklc https://forum.colemak.com/topic/870-hacked-msklc-to-enable-remapping-capslock/ or download and install the layout and switch to it from the language menu https://forum.colemak.com/topic/1621-colemak-for-windows-with-capslock-to-backspace/ and then try to use the backspace.

FreezyLemon commented 6 years ago

See opentk/opentk#666. If I understand this correctly, OpenTK currently uses the physical key location (aka "scancodes") instead of what you set your OS to do with the key (aka windows "virtual key"), so it'll always see the physical keys like they would be used on a US QWERTY keyboard.

yellowsink commented 2 years ago

Occurs for me on Linux too.

peppy commented 2 years ago

We've actually done a lot of work surrounding key input and key codes, to the point I'd wager that the original issue has been fixed (needs confirmation).

@yellowsink can you give more details about your setup to cause issue?

columna1 commented 2 years ago

@ppy I can confirm this is still an issue on windows and linux. Tested with latest osu!lazer build 2021.1225.0-lazer under windows 11 with same repro as original post. Still same issue. Can also confirm that this is an issue under arch linux as well. Under both xorg11 and wayland (which might be xwayland) To reproduce: Set keyboard layout to colemak Issue command: setxkbmap us -variant colemak under x11 Under wayland it depends on the compositor but under swaywm you put this into your config file

input * {
    xkb_layout "us"
    xkb_variant "colemak"
}

Under all cases Capslock does not work as a backspace in osu!lazer where it does work most if not everywhere under the respective OS/environments

Susko3 commented 2 years ago

If you map Capslock in osu! keybind settings, does it show up as Capslock (Caps) or Backspace (BackSp)?

Please test on Windows and Linux, if possible.

columna1 commented 2 years ago

@Susko3 On linux it shows up as BACKSP (x11 vs wayland doesn't matter) On windows it shows up as CAPS

yellowsink commented 2 years ago

We've actually done a lot of work surrounding key input and key codes, to the point I'd wager that the original issue has been fixed (needs confirmation).

@yellowsink can you give more details about your setup to cause issue?

@columna1 has said pretty much all I was going to say. I am running i3wm, but have experienced this in sway too. Also I use Colemak as my primary layout - with the built in setxkbmap colemak us variant.

Susko3 commented 2 years ago

On linux it shows up as BACKSP (x11 vs wayland doesn't matter) On windows it shows up as CAPS

Done a bit of digging, and SDL currently doesn't play nice with remapped non-letter keys on windows. It simply ignores the keymap (relavent code).

We currently use scancodes to map keys, so caps lock key is always treated as caps lock internally in the framework. Switching to keycodes would solve this (at least on Linux). But we must be careful, as keycodes can be any unicode character.

For most of the hotkeys it does make sense to use keycodes (eg. Ctrl+Z - every keyboard layout has a Z somewhere). But for others using a scancode makes more sense (eg. Ctrl++ - not every keyboard has a plus key, some have it in shifted state).

Using physical key position (scancodes) also makes sense for default bindings for gameplay osu!-side. But again, Ctrl+D for direct might not always be a D key.

Not really sure what's the best way to proceed here.

Also relevant: https://github.com/ppy/osu/issues/11143.

bdach commented 2 years ago

Also relevant: https://github.com/ppy/osu-framework/pull/3950

Susko3 commented 1 year ago

@columna1 @yellowsink Could you test this again, but with extended logging enabled:

  1. Set envvar SDL_EVENT_LOGGING=1 (applies to linux and windows)
  2. Run the game
  3. Press caps lock (your backspace) a few times, do it while a textbox is focused and not focused
  4. Close the game and upload the full runtime.log (you should see some lines with SDL EVENT: SDL_KEYUP/KEYDOWN)
columna1 commented 1 year ago

@Susko3 Arch linux wayland (wlroots/labwc) runtime.log

Susko3 commented 1 year ago

Relevant log entry:

SDL EVENT: SDL_KEYDOWN (timestamp=17098 windowid=1 state=pressed repeat=false scancode=57 keycode=8 mod=0)

scancode=57 is SDL_SCANCODE_CAPSLOCK keycode=8 is SDLK_BACKSPACE

Thanks, what I have in mind for the fix should work for you.

If you're able to, please also test on windows.

columna1 commented 1 year ago

If you're able to, please also test on windows.

I no longer have a dual boot/windows machine however I do have a windows 11 VM. and this is what I get: runtime.log Relevant lines seem to be:

2023-06-19 15:36:54 [verbose]: SDL application log [info]: SDL EVENT: SDL_KEYDOWN (timestamp=24591 windowid=1 state=pressed repeat=false scancode=57 keycode=1073741881 mod=8192)
2023-06-19 15:36:54 [verbose]: SDL application log [info]: SDL EVENT: SDL_KEYUP (timestamp=24651 windowid=1 state=released repeat=false scancode=57 keycode=1073741881 mod=8192)
2023-06-19 15:36:54 [verbose]: SDL application log [info]: SDL EVENT: SDL_KEYDOWN (timestamp=24736 windowid=1 state=pressed repeat=false scancode=57 keycode=1073741881 mod=0)
2023-06-19 15:36:54 [verbose]: SDL application log [info]: SDL EVENT: SDL_KEYUP (timestamp=24794 windowid=1 state=released repeat=false scancode=57 keycode=1073741881 mod=0)

I include 4 lines because it seems to flip the mod state as well

Susko3 commented 1 year ago

Thanks for the logs, unfortunately this won't work on windows. I'll report to upstream. In the meantime, remapping with PowerToys Keyboard Manager will work.

scancode=57 is SDL_SCANCODE_CAPSLOCK keycode=1073741881 is SDLK_CAPSLOCK