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

SDL: Some keybinds broken due to missing character lookup #14545

Open
Desour opened this issue Jun 30, 2023 · 18 comments
Open

SDL: Some keybinds broken due to missing character lookup #14545

Desour opened this issue Jun 30, 2023 · 18 comments
Labels
Bug Issues that were confirmed to be a bug @ Client / Controls / Input Regression Something that used to work no longer does
Milestone

Comments

@Desour
Copy link
Member

Desour commented Jun 30, 2023

Opening the chat with / is broken on my keyboard setup. I write it with shift+7. It's instead just interpreted as 7 (= select item in horbar).

@Desour Desour added the Bug Issues that were confirmed to be a bug label Jun 30, 2023
@numberZero
Copy link
Contributor

Shouldn’t key bindings depend on key positions and not on symbols? Otherwise switching a layout would break them (and e.g. I do that often: not all scripts are Latin)

@Desour
Copy link
Member Author

Desour commented Jun 30, 2023

Ideally binding both types of keys should be possible. In the case of /, the written character makes much more sense as the key position.

The thing is, minetest currently allows binding symbols, so to not change user experience, SDL should support this too, imo.

@numberZero
Copy link
Contributor

The thing is, minetest currently allows binding symbols, so to not change user experience, SDL should support this too, imo.

Fixing bugs is changing user experience, too.

Ideally binding both types of keys should be possible.

In theory, maybe. But in practice, that would only confuse players. Key location is simple to understand, simple to code, and always works. While characters... aren’t. There are just too many things that may go wrong with them.

P.S. Default keybindings may need some rethinking too. E.g. I for inventory isn’t all that good, it’s too far from WASD.

@sfan5
Copy link
Collaborator

sfan5 commented Jul 26, 2023

Key location is simple to understand, simple to code, and always works. While characters... aren’t. There are just too many things that may go wrong with them.

A bit off-topic but I don't think it's all that simple.
When you do this you get into the business of needing to display the correct key name to the user (do you save the raw keycode in minetest.conf?). Plus it gets messy when the layout changes.

@numberZero
Copy link
Contributor

do you save the raw keycode in minetest.conf?

Scancode. Not keycode. That’s the whole point.

display the correct key name to the user

SDL_GetKeyName(SDL_GetKeyFromScancode(...)) maybe?

Plus it gets messy when the layout changes.

SDL_GetKeyName apparently uses the layout that was active when SDL_Init was called. Totally fine where the current layout is per-application (so at the init call time, user’s default layout is current). Not that good for global-current-layout systems but acceptable IMO. Much better than movement keys not working due to starting Mesebox with the wrong current layout.

@Montandalar
Copy link
Contributor

I can see two distinct issues here:

  • Certain keys don't register properly, even on the US layout such as `, and the / on the German layout as Desour noted. Those keys can't be bound, or existing custom binds used when bound in earlier, non-SDL versions.
  • The default settingtypes values for increasing and decreasing render distance are invalid for SDL2 compared to pre-SDL irrlichtMt. Either non-SDL needs to be dropped and the defaults fixed, or some kind of compatibility layer needs to be there to ensure the binds work no matter SDL is used or not.

@Montandalar
Copy link
Contributor

@nephele-gh reported needing to rebind sneak from the default "Shift" to "Left Shift" upon switching from 5.8 to 5.9.0-dev on macOS. Render distance is one thing, but having a core gameplay control like sneak broken by default is not good.

I'll reinforce the point in my last comment. I think a clear upgrade path for existing controls is needed: something like either a layer to translate old/existing bind names to SDL ones or at least working new defaults.

@grorp
Copy link
Member

grorp commented May 16, 2024

Note that SDL2 isn't (yet) enabled by default on macOS. The cause of nephele-gh's bug is probably this, which should be disabled when compiling with SDL:

https://github.com/minetest/minetest/blob/bceef8f5293fb935a78d143976fe1a0eecfdf5de/src/defaultsettings.cpp#L541-L544

PR'd a fix: #14754

@grorp
Copy link
Member

grorp commented Jun 16, 2024

It seems that SDL fails to provide the information we need here. Like Desour, I have a German keyboard where slash is Shift + 7. SDL has a keycode named SDLK_SLASH, so I thought we could just listen for that keycode and everything would work.

diff --git a/irr/src/CIrrDeviceSDL.cpp b/irr/src/CIrrDeviceSDL.cpp
index ecea5bac3..6f08d7fa4 100644
--- a/irr/src/CIrrDeviceSDL.cpp
+++ b/irr/src/CIrrDeviceSDL.cpp
@@ -2,6 +2,7 @@
 // This file is part of the "Irrlicht Engine".
 // For conditions of distribution and use, see copyright notice in irrlicht.h
 
+#include <iostream>
 #ifdef _IRR_COMPILE_WITH_SDL_DEVICE_
 
 #include "CIrrDeviceSDL.h"
@@ -817,6 +818,9 @@ bool CIrrDeviceSDL::run()
                        irrevent.KeyInput.Shift = (SDL_event.key.keysym.mod & KMOD_SHIFT) != 0;
                        irrevent.KeyInput.Control = (SDL_event.key.keysym.mod & KMOD_CTRL) != 0;
                        irrevent.KeyInput.Char = findCharToPassToIrrlicht(mp.SDLKey, key);
+                       std::cerr << "got " << (SDL_event.type == SDL_KEYDOWN ? "SDL_KEYDOWN" : "SDL_KEYUP") << ". " <<
+                                       "SDL_event.key.keysym.sym = " << (int)SDL_event.key.keysym.sym << "; " <<
+                                       "Irrlicht key = " << (int)key << "; assumed char = " << irrevent.KeyInput.Char << std::endl;
                        postEventFromUser(irrevent);
                } break;
 

When pressing Shift + 7, I get the following output:

got SDL_KEYDOWN. SDL_event.key.keysym.sym = 1073742049; Irrlicht key = 160; assumed char = 0
got SDL_KEYDOWN. SDL_event.key.keysym.sym = 55; Irrlicht key = 55; assumed char = 55
got SDL_KEYUP. SDL_event.key.keysym.sym = 55; Irrlicht key = 55; assumed char = 55
got SDL_KEYUP. SDL_event.key.keysym.sym = 1073742049; Irrlicht key = 160; assumed char = 0

1073742049 = SDLK_LSHIFT
55 = SDLK_7

SDLK_SLASH is not sent.

While searching the SDL issue tracker, I found this: libsdl-org/SDL#3559

@grorp
Copy link
Member

grorp commented Jun 25, 2024

With the changes to SDL3 coming from libsdl-org/SDL#3559, SDL3 makes it easy to reimplement the behavior of other Irrlicht devices in CIrrDeviceSDL. I have a version that fixes the slash issue here: grorp@48db7e5 (please note that I didn't do the SDL2 -> SDL3 migration properly) (the numpad +/- keys are still not working properly, haven't investigated)

@grorp
Copy link
Member

grorp commented Jun 27, 2024

Numpad +/- fixed by #14780.

@ExeVirus
Copy link
Contributor

So to clarify: the issues remaining are:

  • MacOS using non-SDL backend
  • shift-F7 not mapping to /
  • ` not mapping on US layouts

Anything else?

@grorp
Copy link
Member

grorp commented Jul 2, 2024

The SDL people have done more fancy things to key input for SDL 3 btw: libsdl-org/SDL#10156

@y5nw
Copy link
Contributor

y5nw commented Jul 3, 2024

` not mapping on US layouts

Not just the backtick key. Umlaut keys (e.g. ü) are not mapped either.

Anything else?

Dead keys appear to be mapped to the "Left Button" (left mouse button).

@Zughy Zughy added this to the 5.10.0 milestone Aug 5, 2024
@rubenwardy
Copy link
Contributor

Related: #14940

@sfence
Copy link
Contributor

sfence commented Aug 10, 2024

Looks fine on Mac OS, both in the Minetest build for Intel and ARM.

I tested two keyboard layouts where "/" required normal key press and shift + key press. Works as expected in both states.

@grorp
Copy link
Member

grorp commented Aug 10, 2024

Looks fine on Mac OS, both in the Minetest build for Intel and ARM.

I tested two keyboard layouts where "/" required normal key press and shift + key press. Works as expected in both states.

Our macOS builds don't use SDL by default. To reproduce the issue, you have to build with -DUSE_SDL2=1 explicitly.

@sfence
Copy link
Contributor

sfence commented Aug 10, 2024

Looks fine on Mac OS, both in the Minetest build for Intel and ARM.
I tested two keyboard layouts where "/" required normal key press and shift + key press. Works as expected in both states.

Our macOS builds don't use SDL by default. To reproduce the issue, you have to build with -DUSE_SDL2=1 explicitly.

Oh yes. In the Minetest built on Mac with -DUSE_SDL2=1, shift + key does not open a chat.

@Zughy Zughy modified the milestones: 5.10.0, 5.11.0 Oct 10, 2024
sfan5 added a commit to sfan5/luanti that referenced this issue Oct 13, 2024
sfan5 added a commit that referenced this issue Oct 14, 2024
@Zughy Zughy modified the milestones: 5.11.0, 5.12.0 Jan 21, 2025
sfan5 added a commit to sfan5/luanti that referenced this issue Jan 23, 2025
sfan5 added a commit to sfan5/luanti that referenced this issue Jan 23, 2025
sfan5 added a commit to sfan5/luanti that referenced this issue Jan 23, 2025
sfan5 added a commit that referenced this issue Jan 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Issues that were confirmed to be a bug @ Client / Controls / Input Regression Something that used to work no longer does
Projects
None yet
Development

Successfully merging a pull request may close this issue.

10 participants