You are doing osdev and wrote your nice PS/2 or USB keyboard driver, now you have a bunch of keycodes. Unfortunately, implementing keyboard layouts in a hobby OS is generally very tedious and results in ugly spaghetti code. Not only that, but most osdevers will only hardcode one keymap (or even part of it!). It's very easy to end up with something like this (my own code). There are many examples of this, on pretty much all independent OS: like this one, this one, this one, and this other one.
In order to avoid this in my new OS, I spent an afternoon looking at keymap-related projects. One of them, kbd, implements relatively simple layout files; however, they're still hard to parse, and keymap files form a hierarchy.
kbd2csv
converts this format into very simple to parse CSV files in the lines of:
[keycode],[no modifiers],[shift],[altgr],[left ctrl],[right ctrl]
Such as:
1,Escape,,,,
2,one,exclam,,,
3,two,at,at,,
4,three,numbersign,,,
5,four,dollar,dollar,Control_backslash,
6,five,percent,,,
7,six,asciicircum,,,
8,seven,ampersand,braceleft,Control_underscore,
9,eight,asterisk,bracketleft,Delete,
10,nine,parenleft,bracketright,,
11,zero,parenright,braceright,,
While it does not convey the full functionality of kbd
, it's good enough for independent projects, and turns out to be very low-effort high-reward.
If you want to check out how a driver handles this format, check mine.
Feeling lazy? Download the CSV files directly!
To actually convert the files, clone the official kbd repository and execute kbd2csv
with the layout name to generate the full self-contained CSV layout file:
$ git clone https://github.com/legionus/kbd
$ git clone https://github.com/jlxip/kbd2csv
$ cd kbd2csv && cargo build --release
$ target/release/kbd2csv ../kbd/data/keymaps/i386/qwerty/us.map us.csv
Pretty please link to this project if you end up using files generated by it.