-
-
Notifications
You must be signed in to change notification settings - Fork 538
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
Map SDL_SCANCODE_GRAVE to the console key. #285
base: main
Are you sure you want to change the base?
Conversation
This makes complete sense if it actually works. Sadly in the field testing of the scancode support in SDL did not go well. However, that was very soon after SDL 2 was released so hopefully it's better now. |
In the field it always maps to that key. But the issue is is that key is sometimes ^ or other possibly conflicting ones. |
mickael9, for a long time (since SDL2) opening console on german keyboard is a real disaster, I can only open console with Alt Gr + ~ |
This was my solution. |
one potential problem is that on the Brazilian keyboard layout, Can't people just use Shift+Esc to open the console? Or bind one of the F keys or sth |
Alternatively you can also maybe add an alt key modifier when held to not process it as a console key, and proceed as text input for the above case too maybe ^ @DanielGibson ? |
so Alt+Key should give ' or " instead of opening/closing console? or the other way around? |
Does anyone of you understand what exactly the real problem behind all this is with SDL2? |
it was a problem with 1.2, but as 1.2 didn't have (consistent) scancodes it wasn't solvable, so I think the "solution" was to just add support for Shift+Esc which works everywhere |
Ah thanks! In Spearmint (ioquake3 based) even Shift+Esc won't work (at least on a german keyboard). Didn't know about differences of ioquake3 forks,..., so Shift+Esc ,should' work on all layouts, but is not guaranteed? |
How about translating keys to their QWERTY-equivalent keycode and using that to compare against This would work by default, and Brazilian keyboard users can change it to avoid conflicts with the I'm not sure if matching against characters (rather than keys) in |
Shift+Esc should work if the game/port has code to support it. And even OTOH I think I used the SDL_SCANCODE_GRAVE hack in some games (Daikatana and Yamagi Quake2, not sure about dhewm3 and RBD3BFG right now) and no one ever complained - but that doesn't mean it's not really a problem, it just means that so far there were no people from Brazil who use those games/ports and use the console and tried to input |
Yeah, the ^ key is for colored text on german keyboard. |
This PR would cause that I cannot write any ^ chars in the console anymore, since it would close the console instantly. As solution I propose to simply check if the console text is empty. We gotta add the special cases over time, atm I added for German/Brasilian keyboards. @DanielGibson Could you try this code, if it works for you? Probably it only needs one case, ' or ". Based on the Brasilian keyboard screenshot I've seen, it's probably ' (the lower one). In code:
Thanks for the PR btw, this triggered me to check this console key issue again. Finally it feels "right". |
Thanks for the feedback. I think we probably don't want this if that key is useful on German and Brazilian layouts (and likely others). We can add the @ensiform's solution doesn't work for Brazilian keyboards, and German layout users have to use Shift which makes it a bit useless (just use The currently implemented solution matches both by characters and keys, which seems to be a good compromise:
@kungfooman Unfortunately there are many other layouts and conflicting keys, for instance BÉPO has I have created a quick script that extracts all the possible symbols from all layouts for that key and this was the result (including only latin chars): https://git.io/vSgy0. There are probably bogus entries in there but it gives an idea. Anyway, I think if we're going for your method (which IMHO is clearly an improvement over the current implementation), we might as well do the opposite and consider it a conflict if it matches any ASCII character in the 32-127 range except Something like this (untested): diff --git a/code/sdl/sdl_input.c b/code/sdl/sdl_input.c
index 4c8ff1fe..66b380f8 100644
--- a/code/sdl/sdl_input.c
+++ b/code/sdl/sdl_input.c
@@ -191,11 +191,13 @@ IN_TranslateSDLToQ3Key
static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, qboolean down )
{
keyNum_t key = 0;
+ qboolean is_ascii = qfalse;
if( keysym->sym >= SDLK_SPACE && keysym->sym < SDLK_DELETE )
{
// These happen to match the ASCII chars
key = (int)keysym->sym;
+ is_ascii = qtrue;
}
else
{
@@ -291,6 +293,15 @@ static keyNum_t IN_TranslateSDLToQ3Key( SDL_Keysym *keysym, qboolean down )
{
// Console keys can't be bound or generate characters
key = K_CONSOLE;
+ } else if ( keysym->scancode == SDL_SCANCODE_GRAVE ) {
+ // We want the QWERTY grave key location to always match the console (whatever the layout)
+ // Since this can map to other useful keys, we only do this if:
+ // - Either the key is not in the ASCII range or is one of '~' and '`'
+ // - Or we have no key catchers set and the console field is empty
+ qboolean console_has_text = strlen(g_consoleField.buffer) > 0;
+
+ if ( !is_ascii || key == '~' || key == '`' || ( !Key_GetCatcher() && !console_has_text ) )
+ key = K_CONSOLE;
}
return key; |
I don't have a Brazilian keyboard, just a German one - I only saw that layout somewhere (probably https://en.wikipedia.org/wiki/Portuguese_keyboard_layout#/media/File:KB_Portuguese_Brazil.svg) Anyway, I like the idea of toggling the console with SDL_SCANCODE_GRAVE, but only if the console line empty - this should work even without checking all the potential key codes that key could have? |
@DanielGibson: We could completly drop the conflict checking and just close console when it has no input. I just wanted to keep the old behaviour for people who are used to it (closing console even tho it has text - I don't even know if that's the default behaviour lol). @mickael9: The ASCII idea seems ideal to detect the special cases. The keycatch idea is also great, so I can use ^ again in chat to color the chat text. Using only I got this code so far, which works at least on German keyboard, so would be great if all kinds of keyboard layout users could test it aswell:
|
Something something, I told you so. |
@timangus This has nothing to do with SDL though, it's about the inherent problems with the key itself which has other uses in some layouts |
Fair enough. I remember it being problematic when I originally wrote it, but don't recall the specifics. |
Although I just found something that might be a SDL2 bug. |
Currently, the only way to invoke the console which is both platform and layout independent is to use Shift+Escape. This change makes sure the QWERTY '`' key (at the left of the 1 key) works as a console key and for all keyboard layout by matching against its scan code (ie physical location). Since this key can also be mapped to normal characters that could be useful for text input (eg, '^' on German keyboards), we only interpret it as a console key if one of those conditions is respected: - The resulting key is valid and outside ascii range (0x20-0x7f) - The resulting key is '~' or '`' - The console input field is empty and no chat message is being written Additionaly, no modifiers (Shift, Ctrl, Alt, AltGr, Ctrl, Super/Win) shall be pressed to allow usage of the keys in the Shift/AltGr group and to allow bypassing the console (Alt works on X11, Windows key must be used on Windows) A new `cl_consoleUseScanCode` cvar (default 1) is added to enable the feature.
2df5890
to
a455e98
Compare
I have updated this PR with changes to avoid conflicts, let me know if this is any better. |
Yeah, X11 doesn't have mapping for dead keys, so the standard mapping based on the scancode is used, see https://bugzilla.libsdl.org/show_bug.cgi?id=2071 If you use a German layout without dead keys, you should get the expected |
@DanielGibson I tested this, using
Is that what the "standard mapping for scancodes", is supposed to be? There is no valid keycode at all in there. |
hmm weird, I think that back when I tested, I'd get a backtick as sym in that case. Like I would in untranslated US layout. |
Ok, I think I found the bug in SDL, will create an issue there later. The behavior I get in ioquake3 then is (without your patch):
Pressing that key will open/close the console, as the keycode is like on US keyboard. I think that will break your patch, especially the Just never closing the console if there's any text in the input line should help. People should be able to get used to clear the line (e.g. with Ctrl-C or Arrow-Down) before closing the console with the "Console Key". UPDATE: Pro-Tip: to write a backtick in inline code blocks, surround them with two backticks instead of just one, like
|
Created a bugreport for SDL: https://bugzilla.libsdl.org/show_bug.cgi?id=3624 |
I'm not entirely convinced that giving a wrong "default" is better than just giving an unknown keycode ( Hopefully there is a way to actually get the right key though?
For comparison, this is what I get with the non-dead
The keysym is EDIT: apparently, with a dead keys there are two consecutive KeyPress, where the two LookupString alternate being empty With or without my patch, German keyboard users won't be able to type Nice pro-tip, I used |
It's almost 4 years ago I debugged X11/dead key stuff for SDL, so I don't remember all the details.. but it could be that xev has some information SDL2 doesn't, because SDL2 calls XFilterEvent() and xev probably doesn't. This is the original patch to SDL2 to get events for dead keys: https://hg.libsdl.org/SDL/rev/713c6a333c33 Related links discussing this issue for SDL2: https://bugzilla.libsdl.org/show_bug.cgi?id=2071 https://forums.libsdl.org/viewtopic.php?p=38900#38900 Anyway, if you can figure out a way for SDL2 to get the proper keysym (while still supporting dead keys for textinput) that'd be cool and you should mention it at https://bugzilla.libsdl.org/show_bug.cgi?id=3624 :) |
Currently, the only way to invoke the console which is both platform and
layout independent is to use Shift+Escape.
This change makes sure the QWERTY '`' key (at the left of the 1 key)
works as a console key and for all keyboard layout by matching against
its scan code (ie physical location).
Since this key can also be mapped to normal characters that could be
useful for text input (eg, '^' on German keyboards), we only interpret
it as a console key if one of those conditions is respected:
Additionaly, no modifiers (Shift, Ctrl, Alt, AltGr, Ctrl, Super/Win)
shall be pressed to allow usage of the keys in the Shift/AltGr group and
to allow bypassing the console (Alt works on X11, Windows key must be used
on Windows)
A new
cl_consoleUseScanCode
cvar (default 1) is added to enable thefeature.