Questions on remapping the keyboard

Friends, I’m reading the handbook on how to remap the keyboard, but I’m afraid I don’t quite understand what to do exactly. I do apologise if I have missed a piece of documentation explaining it.

The handbook as well as the repo’s readme say I should edit the matrix arrays in keyboard.c, but I think they have been moved out to matrix.h and matrix_v.h perhaps? If so it is still unclear how to change the key mapping. The things I’d like to do are:

  • Turn HYPER to CTRL
  • Turn CTRL that’s under TAB to HYPER
  • Turn CTRL that’s between MNT and left space to ALT
  • Disable the … key (unless someone recommends a good use for it)
  • Turn the two ALTs between the space keys into space keys

If someone could tell me how to change one of the above I think I should be able to figure out the rest. Thanks!

Hej!
I changed the right part of the space bar to Ctrl by modifying Keyboard.c. The corresponding patch is:

diff --git a/reform2-keyboard-fw/Keyboard.c b/reform2-keyboard-fw/Keyboard.c
index 1dc1310..38aba7d 100644
--- a/reform2-keyboard-fw/Keyboard.c
+++ b/reform2-keyboard-fw/Keyboard.c
@@ -60,7 +60,7 @@ uint8_t matrix[COLS*6+2] = {
 
   HID_KEYBOARD_SC_LEFT_SHIFT, HID_KEYBOARD_SC_NON_US_BACKSLASH_AND_PIPE, KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, HID_KEYBOARD_SC_COMMA_AND_LESS_THAN_SIGN, HID_KEYBOARD_SC_DOT_AND_GREATER_THAN_SIGN, KEY_SLASH_AND_QUESTION_MARK,  HID_KEYBOARD_SC_UP_ARROW, HID_KEYBOARD_SC_RIGHT_SHIFT,
 
-  HID_KEYBOARD_SC_RIGHT_GUI, HID_KEYBOARD_SC_LEFT_GUI, HID_KEYBOARD_SC_RIGHT_CONTROL, KEY_SPACE, HID_KEYBOARD_SC_LEFT_ALT, HID_KEYBOARD_SC_RIGHT_ALT, KEY_SPACE, HID_KEYBOARD_SC_PAGE_UP, HID_KEYBOARD_SC_PAGE_DOWN, HID_KEYBOARD_SC_LEFT_ARROW, HID_KEYBOARD_SC_DOWN_ARROW, HID_KEYBOARD_SC_RIGHT_ARROW,  0xfe,0xed,0xca,0xfe
+  HID_KEYBOARD_SC_RIGHT_GUI, HID_KEYBOARD_SC_LEFT_GUI, HID_KEYBOARD_SC_RIGHT_CONTROL, KEY_SPACE, HID_KEYBOARD_SC_LEFT_ALT, HID_KEYBOARD_SC_RIGHT_ALT, HID_KEYBOARD_SC_RIGHT_CONTROL, HID_KEYBOARD_SC_PAGE_UP, HID_KEYBOARD_SC_PAGE_DOWN, HID_KEYBOARD_SC_LEFT_ARROW, HID_KEYBOARD_SC_DOWN_ARROW, HID_KEYBOARD_SC_RIGHT_ARROW,  0xfe,0xed,0xca,0xfe
 };
 
 /** Buffer to hold the previously generated Keyboard HID report, for comparison purposes inside the HID class driver. */

But note that changing the actual keyboard firmware is not the only way you can change the keyboard mapping. I documented how I added a SysRq key on the OS level using udev which should also work for other keycodes: Remapping keyboard without firmware modification (adding SysRq key) - #3 by Chartreuse

To actually make use of the Hyper key as such (I think it acts by default as “right GUI/logo” key), you will also have to adjust the xkb config to map that modifier key. I haven’t written that part down yet but intend to do so soon.

Best of luck!

Hey @doctorhoo thank you for your help!

It seems like the matrix array has been moved out of keyboard.c.

What I don’t understand is what is the difference between matrix.h and matrix_v.h. Does anybody happen to know?

I’ve been looking into remapping the keyboard as well and it looks like the default keys are mapped in keyboard.h . I think matrix.h is for special layers toggled by hyper key and hyper+circle. Haven’t tested poking around those files and building the layout i want, i’ll report back here if it works how i think it does.

1 Like

@chipperoodles ah, yes you’re right! It is quite trivial in fact to change them, thank you!

This is how I ended up tweaking the keyboard itself (the HYPER key is actually ALT):

2 Likes

@friendofmegaman Thank you for sharing your layout! I ended with the same changes, but also switched the z and y keys to get a franken-qwertz layout.

Having looked at the german layout for the Reform, i decided to stick with the us layout.

I have a 4.0 keyboard with German layout. In reform2-keyboard4-fw/src/matrix.h I did not find an QWERTZ Configuration with German umlaut keys. Is this the correct fw src for this type of keyboard?

Typically you would not change the firmware if you want to switch the “language” of your keyboard. You’d just switch the keyboard layout in your desktop environment.

I do not want to change the language but I want to change some keys. Add DEL with HYPER+BACKSPACE, swap SUPER - CTRL.
I am confused that the layout in matrix.h does not match my hardware, and I fear that I brick it if I compile and upload the wrong one.

That’s not what you said above, where you said “I did not find an QWERTZ Configuration with German umlaut keys”. There is no such firmware. You do not change to qwertz by changing the firmware but by changing XKBLAYOUT either in /etc/default/keyboard or by running dpkg-reconfigure keyboard-configuration.

I don’t think you can brick your keyboard by uploading the wrong firmware. The DIP switches should always allow you to go back into DFU programmer mode where you can flash a fixed firmware in case the one you flashed turns out to be broken somehow.

If you have keyboard 4.0, then this should be the correct matrix.h to change if you want to swap SUPER and CTRL:

1 Like