Opened 11 years ago
Last modified 11 years ago
#2043 closed enhancement
[PATCH] Adding some azerty keymapping for the hotkeys — at Version 16
Reported by: | lsdh | Owned by: | |
---|---|---|---|
Priority: | Should Have | Milestone: | Alpha 14 |
Component: | Core engine | Keywords: | simple patch |
Cc: | Patch: |
Description (last modified by )
On Linux (tested on Ubuntu 13.4 with gnome shell); the hotkeys ctrl+1 to ctrl+0 did not work natively in my case (but does in Windows 7, same computer, same keyboard layout). I have a Belgian keyboard, so default keymapping is really different from the US one.
A ~/.config/0ad/config/local.cfg can receive modifications to have custom hotkeys, but some keys I needed where not available: § à ç è é
Theses keys are (in sdl 1.2) part of the SDLK_WORLD keys.
Unfortunately, the numbers used are not always the same (at least different in OSX with french keyboard).
To allow people to have a full ctrl+1 to ctrl+0 bar without changing the sources and to anticipate the possible keypapping in the GUI, I added the full SDLK_WORLD key list in the /0ad/source/ps/Keyname.cpp list.
As the SDLK_WORLD are no more there in sdl2, I putted the definition there:
#if SDL_VERSION_ATLEAST(2, 0, 0) { SDLK_KP_0, "Numpad 0", "Num0" }, . . . { SDLK_KP_9, "Numpad 9", "Num9" }, #else == { SDLK_WORLD_0, "World0", "W0" }, . . . { SDLK_WORLD_95, "World95", "W95" }, == { SDLK_KP0, "Numpad 0", "Num0" }, . . . { SDLK_KP9, "Numpad 9", "Num9" }, #endif
And configured the ~/.config/0ad/config/local.cfg like this:
hotkey.selection.group.select.0 = W64 hotkey.selection.group.save.0 = "Ctrl+W64" hotkey.selection.group.add.0 = "Shift+W64" hotkey.selection.group.select.1 = Ampersand hotkey.selection.group.save.1 = "Ctrl+Ampersand" hotkey.selection.group.add.1 = "Shift+Ampersand" hotkey.selection.group.select.2 = W73 hotkey.selection.group.save.2 = "Ctrl+W73" hotkey.selection.group.add.2 = "Shift+W73" hotkey.selection.group.select.3 = DoubleQuote hotkey.selection.group.save.3 = "Ctrl+DoubleQuote" hotkey.selection.group.add.3 = "Shift+DoubleQuote" hotkey.selection.group.select.4 = SingleQuote hotkey.selection.group.save.4 = "Ctrl+SingleQuote" hotkey.selection.group.add.4 = "Shift+SingleQuote" hotkey.selection.group.select.5 = LeftParen hotkey.selection.group.save.5 = "Ctrl+LeftParen" hotkey.selection.group.add.5 = "Shift+LeftParen" hotkey.selection.group.select.6 = W7 hotkey.selection.group.save.6 = "Ctrl+W7" hotkey.selection.group.add.6 = "Shift+W7" hotkey.selection.group.select.7 = W72 hotkey.selection.group.save.7 = "Ctrl+W72" hotkey.selection.group.add.7 = "Shift+W72" hotkey.selection.group.select.8 = Exclaim hotkey.selection.group.save.8 = "Ctrl+Exclaim" hotkey.selection.group.add.8 = "Shift+Exclaim" hotkey.selection.group.select.9 = W71 hotkey.selection.group.save.9 = "Ctrl+W71" hotkey.selection.group.add.9 = "Shift+W71"
The /0ad/binaries/data/config/keys.txt should also be updated to warn theses keys are available.
I could manage to do this changes thanks to Philip` and RedFox| on the IRC, so a big thanks to them.
(To know which SDLK_WORLD number correspond to a keys, you can temporary add the line
printf("%d %d\n", ev->ev.type, (int)ev->ev.key.keysym.sym);
in the HotkeyInputHandler function of /0ad/source/ps/Hotkey.cpp then compile and launch the game in a terminal. An integer will be displayed when a key is pressed:
2 224 3 224
The second number (224 here) correspond to the key and this http://www-personal.umich.edu/~bazald/l/api/_s_d_l__keysym_8h.html will give you the SDLK name corresponding).
Change History (17)
comment:1 by , 11 years ago
Description: | modified (diff) |
---|
comment:2 by , 11 years ago
Description: | modified (diff) |
---|
comment:3 by , 11 years ago
comment:4 by , 11 years ago
Keywords: | patch added; Keyname removed |
---|---|
Priority: | If Time Permits → Should Have |
Summary: | Adding some Belgian keymapping for the hotkeys → [PATCH] Adding some Belgian keymapping for the hotkeys |
comment:5 by , 11 years ago
I'll update tomorrow.
In fact, the only two files that should be in the snv diff are the KeyName.cpp and the keys.txt. the .cfg file is there if people wants to easily have it to works and the Hotkey.cpp can be deleted from the list (it only contain the commented line, so it does not helps).
With theses changes, the keys would be right for Belgian and French azerty keyboards (with little double usage of - as this key is already used for zoom-).
I see that most qwerty keyboards have the numbers at this place, so not causing problem I guess, but some special keyboards still exist, like the Lithuanian one.
Does it worth I add their specials keys?
Thanks for your interest :-)
comment:6 by , 11 years ago
Description: | modified (diff) |
---|---|
Summary: | [PATCH] Adding some Belgian keymapping for the hotkeys → [PATCH] Adding some azerty keymapping for the hotkeys |
comment:7 by , 11 years ago
Keywords: | review added |
---|
comment:8 by , 11 years ago
Milestone: | Backlog → Alpha 14 |
---|
Replying to lsdh:
On Linux (tested on Ubuntu 13.4 with gnome shell); the hotkeys ctrl+1 to ctrl+0 did not work natively in my case (but does in Windows 7, same computer). I have a Belgian keyboard, so default keymapping is really different from the US one.
That's unfortunate, it seems SDL2 will have a better system with virtual keys that map to physical keys, respecting layouts, but until then I guess you'll need different hotkeys :(
Do we know that e.g. SDLK_WORLD_71
will always map to 'ç' or does that only apply to some European/Belgian keyboard layouts? The SDL 1.2 documentation doesn't say so.
comment:9 by , 11 years ago
Tested on a French Apple keyboard... And to put shortly it won't work.
"Eacute" would be SDLK_WORLD_0, "Eagrave" would be SDLK_WORLD_3, "Agrave" would be SDLK_WORLD_4 and "Ccedil" would be SDLK_WORLD_2. SDLK_WORLD_1 is probably something like ù.
comment:10 by , 11 years ago
Description: | modified (diff) |
---|
comment:11 by , 11 years ago
If there is no general rule for the SDLK_WORLD_x to correspond to a key, an idea could be to add the whole list of SDLK_WORLD_0 to SDLK_WORLD_95, with generics names (ea W0 to W95). Having all the list would also increase the range of compatibility (the Lithuanian keys could be in theses places).
Than each user would just have to manage to find the needed ones for him.
The main problem is that it is not trivial to know witch keys represent the willing ones (need to capture the keysym, than make the conversion to the Wnumber).
But, there is still a feature that is not yet usable, the "Tool & options> Options" in the gui. This type of option could do this job: The player press the key related to the shortcut he wants, and the computer handle the more tricky parts.
So, until the "Tool & options> Options" is not yet implemented, the whole list could however be added so people that would be interested to config themselves would have exactly the same sources and bin, just the config file would be different.
I just hope adding theses 96 more keys would not slow the game (I think it would be negligible, but I'm not en expert).
What's your point of view?
comment:12 by , 11 years ago
Right, eventually we should be able to set hotkeys in-game. As a workaround we could add some code to optionally display the SDLKey
name of pressed keys, to make it easier to add hotkeys for non-US keyboards.
I wouldn't expect there to be any performance impact from having more possible keys, and they won't even be used by default. One thing to consider is whether/how this works with our Windows SDL emulation. You say the hotkeys already work in Windows, are you using a Belgian layout there?
Also I'm planning to switch to SDL2 on Windows, it's more reliable than our custom emulation and has better multimonitor support. But it will be annoying if we add many new hotkeys that don't have a match in SDL2 (SDL_Keycode doesn't have generic "world" keys).
follow-up: 14 comment:13 by , 11 years ago
Yes, I'm using Belgian Layout under Windows 7.
It's possible that this W7 has sdl2, that could explain the thing as there is already some "#if SDL_VERSION_ATLEAST(2, 0, 0)" compiler tags (Didn't explicitly check if it works both on alpha13 and SVN, but I think so).
In this list for SDL version before 2: http://sdl.beuc.net/sdl.wiki/SDLKey (all our list is in this order, just the world keys and a few others are missing), the place of the worlds key are before the numpad keys:
#if SDL_VERSION_ATLEAST(2, 0, 0) { SDLK_KP_0, "Numpad 0", "Num0" }, { SDLK_KP_1, "Numpad 1", "Num1" }, { SDLK_KP_2, "Numpad 2", "Num2" }, { SDLK_KP_3, "Numpad 3", "Num3" }, { SDLK_KP_4, "Numpad 4", "Num4" }, { SDLK_KP_5, "Numpad 5", "Num5" }, { SDLK_KP_6, "Numpad 6", "Num6" }, { SDLK_KP_7, "Numpad 7", "Num7" }, { SDLK_KP_8, "Numpad 8", "Num8" }, { SDLK_KP_9, "Numpad 9", "Num9" }, #else { SDLK_WORLD_0, "World0", "W0" }, . . . { SDLK_WORLD_95, "World95", "W95" }, { SDLK_KP0, "Numpad 0", "Num0" }, { SDLK_KP1, "Numpad 1", "Num1" }, { SDLK_KP2, "Numpad 2", "Num2" }, { SDLK_KP3, "Numpad 3", "Num3" }, { SDLK_KP4, "Numpad 4", "Num4" }, { SDLK_KP5, "Numpad 5", "Num5" }, { SDLK_KP6, "Numpad 6", "Num6" }, { SDLK_KP7, "Numpad 7", "Num7" }, { SDLK_KP8, "Numpad 8", "Num8" }, { SDLK_KP9, "Numpad 9", "Num9" }, #endif
So I will do like this, and test to compile under W7 to see if all still works correctly.
comment:14 by , 11 years ago
Replying to lsdh:
Yes, I'm using Belgian Layout under Windows 7.
It's possible that this W7 has sdl2, that could explain the thing as there is already some "#if SDL_VERSION_ATLEAST(2, 0, 0)" compiler tags (Didn't explicitly check if it works both on alpha13 and SVN, but I think so).
You would know if you were using SDL2 because you would have to disable our "wsdl" that is hardocded in the engine, and change the build system slightly, and have SDL2 dev libraries compiled and placed in our libraries directory so the game finds them :) And if you're using the latest SDL2 release candidate, you would have to fix the build breakages described on #2041.
(The Windows build doesn't even use the v1.2 SDL.dll in binaries/system, because it's buggy)
comment:15 by , 11 years ago
So I definitely do not use the sdl2.
I made the new /0ad/source/ps/Keyname.cpp. It works well on my Ubuntu 13.04 64bit (once the local.cfg set accordingly to the new names). It works well on my Windows 7 64bit (if no local.cfg, still working like before, if the ubuntu local.cfg, the shortcut do not work as expected).
Thanks for the cleaning of the files. This is more clear now.
For the /0ad/binaries/data/config/keys.txt ; it may be a good idea to add the information that theses World1 to World95 are also available.
by , 11 years ago
Attachment: | KeyName.cpp.patch added |
---|
Adding the SDLK_WORLD_0 to SDLK_WORLD_95 keys.
comment:16 by , 11 years ago
Description: | modified (diff) |
---|
Some comments:
But thanks for the time, it's certainly worth supporting extra keys.