QMK, macros & non-US keyboard layouts
QMK is a great piece of software that can run as firmware on (custom) keyboards. It’s mostly used by keyboard geeks on their ultra expen…custom keyboards to give these keyboards near-magical properties, like making a Planck keyboard usable (or so I’ve been told, at least)!
As with everything else in technology, the primary enthusiasts are US-centric, which makes using other characters than ASCII a bit of a pain, and even though this is steadily improving it’s still not particularly fun today.
Anyways, I use a custom keyboard that runs QMK at my job. Being something of a programmer, I like to waste time on hacks that won’t save me any time, so I’ve naturally automated a boring task with my keyboard - writing my email signature automatically, even when using Swedish characters!
It seems that every time you press a key, a scancode is sent over USB to your operating system. This scancode is then mapped to a keycode, and this mapping is dependent on how your operating system has been configured for keyboard input.
So, when I press the same key that on an American keyboard produces a semicolon (;), an ö is produced onscreen when using a Swedish keyboard setting on my operating system.
This is great, at least when our macros rely on non-ASCII characters that fit into the normal layout we need.
First, create a custom keycode:
enum custom_keycodes {
REGR, // As in: Regards
HALS, // As in: Hälsningar
};
And then, in your process_record_user
function, handle these keycodes:
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case HALS:
if (record->event.pressed) {
SEND_STRING("H'lsningar,\nOscar\narbetsplatsnamn\n");
}
break;
case REGR:
if (record->event.pressed) {
SEND_STRING("Regards,\nOscar\nwhereiwork\n");
}
break;
}
return true;
}
Above, I’m using SEND_STRING
as documented. But, if you look at the
HALS
case above again, you’ll hopefully notice the apostrophe in the function
args. It seems that SEND_STRING
has a translation table between ASCII sent
to it and scancodes, and it translates this to the scancode used for ä on a
Swedish keyboard.
So, after mapping a key to use HALS
, my complete email signature is printed
like expected when using a computer configured to use a Swedish keyboard layout.
Had I used a computer with an American keyboard layout an apostrophe would have
been printed instead.
It’s not much, but it really kinda helps me in my day to day life.
Regards,
Oscar
whereiwork