Custom Keyboard bindings in Emulation Station and console
I am building a raspi inside a c64 case. The keyboard is connected via keyrah v2, which works ok, but the keyboard layout is all over the place. So I would love to create a custom layout for this keyboard.
What I am looking for is a way to create a custom layout keyboard and run it on boot. I am not that well versed in linux, but I am savy enough that when pointed to some software I can work out the kinks myself. This is what I want to achieve:
- Read system keycodes for each key, so I can write out my custom layout (e.g when I press C= key on the keyboard, I want to know what value rasbian receives e.g 52).
- assign what each system value referes to, e.g 52 (the C= key) would act as Crtl
- the program should also allow for non-standard modifiers. E.g Shift+Down Arrow would read as Up Arrow. This is really important to me, as C64 keyboard uses a lot of modifiers (arrows, function keys, etc.)
- a way to have the program run my custom keyboard layout on boot so it can be accessible in terminal and any other program (e.g emulation station).
I have found a mention of xmodmap on the official raspberry pi forums, which seems to allow a custom layout setup. But, from my limited knowledge of linux, I think that because it is a mod for X it might only work in graphical engine and not in console/command line. Will it at least work in emulation station?
Thanks in advance
Cybrasty last edited by
I thought I will post my findings so far.
- xmodmap only wants to run in terminal when in X (pixel desktop) so that's a no go, not to mention it still doesn't seem to accept my change for Shift + Down = Up. (This prints A or D or something instead, and apparently it is some kind of leftover from 80s linux :/ )
- I Think have found the folder where the keyboard layouts are stored in raspbian (those are the tables that are referenced inside /etc/default/keyboard ). Those however seem to be split in a way I don't really grasp (any linux gurus around know how I would like few bindings by editing those?). Also, it seems that every distro keeps them in a different folder. I found them inside /usr/share/x11/kbd/ but I think they might only be references for the x. Is emulation station running on X11?
- Another problem I have run into is in EmulationStation. The GUI keybinder does not want to accept multiple keys as input. Is there a way to setup multikey as input (e.g Shift or Alt + Down as UP)? If so, where would I find the docs to change that and how I would make it (an example of the syntax for Shift + Key or Crtl+Key would be awesome)
I did not think that rebinding the keyboard would be such a hassle. It seems that the main culprit is some legacy code and this byzantine organization of keyboards tables.
I managed to change the virtual console layout by using loadkeys and following this topic.
I will eventually do a write-up for that part, but it didn't solve all my problems.
It seems Emulation Station does not use the console map for keyboard. I have read it is also not using X11. So my question now is:
Where is the default keyboard map for Emulation Station stored? I don't mean the .cfg generated by EmulationStation, but the actual system keyboard tables that the software uses.
And a follow up question, can you make Emulation Station accept modifier keys like Shift or Alt when pressed with a button for it's keyboard .cfg? E.g Right reads as Right, but Shift+Right reads as left?
Cybrasty last edited by
So I finally found out how raspi handles the keyboard (which tables it uses). If you setup your keyboard through the raspi config menu in emulation station (or use dpkg-reconfigure keyboard-configuration in console) it uses tables from: /usr/share/X11/xkb/symbols/
Those tables are used both for X and console, so changing your keyboard in that one place affects both graphical and text mode.
By modifying the location file in symbols (us for me) you can add functions to the keyboard. I based mine on pc file from /digital_vndr/ to find the codes for arrow keys.
That's the good news. The bad news is that those changes don't seem to work in EmulationStation. It seems that either it captures Shift on it's own, or it is using different tables than the one everything else in raspi uses. So, the search continues.
If anyone has any ideas, please do share!
. The bad news is that those changes don't seem to work in EmulationStation
You can run Emulationstation with the
--debugswitch form the command line and look in the log file (
es_log.txt) to see what it captures when you're trying to run the input configuration.
I think I have zeroed-in on the issue (but not solved it yet). The missing puzzle piece was SDL.
Emulationstation is built on top of SDL, which has its own keyboard library. Something is not accounting for modifier keys: either the SDL the way emulationstation is written.
I think there is still hope as the debug log (see end) can see that both Arrow key and Shift and it even shows that my keys are mapped to both down and up in es_input.cfg. Just need to find a way to access that second option in some way.
Anyone has an idea how I can access the second value of my key, or knows their way around emulationstation source so I can add the function myself?
I found where F4 is hardcoded for emulation station, which makes me think I can hardcode arrows + shifted arrows in a similar manner. It is not a great solution, but it is something...
The only problem I have is that I don't know how to build my own version of emulation station with the changes if I made a copy to my own github.
Also, I don't know SDL well enough to code it myself. Anyone able to translate my pseudocode into actual SDL and cpp?
IF keydown(shift) AND keydown(down) THEN return up END
Also, happy to hear any other solutions!