Skip to content

Instantly share code, notes, and snippets.

@Joao-Peterson
Last active November 14, 2024 02:55
Show Gist options
  • Save Joao-Peterson/d9b327b17933a128ee6d94c4c418df0c to your computer and use it in GitHub Desktop.
Save Joao-Peterson/d9b327b17933a128ee6d94c4c418df0c to your computer and use it in GitHub Desktop.
Using GMK67 keyboard in linux with key remaps!

GMK67 with Linux!

Recently i bought a zuoya gmk67 keyboard, it doesn't have a function keys row and has a know for volume control. Unfortunately, if you plug your gmk67 in a linux machine you will notice that using fn+1 will not produce f1 as expected, it will produce a screen brightness decrease, and if you change the physical switch in the back for the macOS mode, the function keys now work, but the modifier keys don't, quite stressful.

Fear not, you can either remap the keys, as in this gist, or alter your system configuration so the keyboard functions normally, as seen in the gist Using GMK67 keyboard in linux. Function keys not working with Fn!.

For this gist, we can simply remap some keys while the physical switch in the back is in windows mode. For that let's install keyd, a remapping tool daemon.

Install

For aarch linux use:

$ yay -S keyd

I know you are smart, you can figure how to install on other distros ;)

Then start teh daemon:

$ sudo systemctl enable --now keyd

Config

Create the following file:

/etc/keyd/gmk67.conf:

###
# GMK76 remap config file
###

[ids]

# all interface (BT, USB, 2.4Ghz dongle)
k:05ac:024f

[main]

# Maps capslock to escape when pressed and control when held.
# capslock = overload(control, esc)

# Remaps the escape key to capslock
#esc = capslock

brightnessdown = f1
brightnessup = f2
scale = f3
dashboard = f4
kbdillumdown = f5
kbdillumup = f6
previoussong = f7
playpause = f8
nextsong = f9
mute = f10
volumedown = f11
volumeup = f12

# activates nav while held, but a tap is a normal capslock
capslock = overload(nav, capslock)

[nav]

up = pageup
down = pagedown
left = home
right = end

[meta]

mute = playpause
volumedown = volumedown
volumeup = volumeup

Then run this command to load the config:

$ sudo keyd reload

And bam, it now works!

Explanation

This config works by remapping the multimedia events firectly into function keys, furthermore, while doing this the knob will stop working as it will produce function keys instead of the volume control we want, so we bind a key, meta, so teh know will emit volume control if we do meta+knob.

In the top we also see a id section, this matches the physical vendor id of your device, in this case mine appears as 'Apple, Inc. Aluminium Keyboard (ANSI)'. You can check yours using:

$ lsusb

or by using keyd monitor and seeing the vendor id while typing something.

$ sudo systemctl stop keyd
$ sudo keyd monitor
  • If you dont want to do any of this, just change the id to *. This will match all keyboards in your machine

As a bonus i remapped capslock to be used as a key modifier for the directional arrows and map them to pgup, pgdown, home and end respectively

@butterdori
Copy link

Another method is to simply
echo 0 | sudo tee /sys/module/hid_apple/parameters/fnmode
This could be reset when rebooting. To prevent this edit the following file
sudo vim /etc/modprobe.d/hid_apple.conf

If there is nothing there simply enter
options hid_apple fnmode=0

And then rebuild the initramfs. For Arch Linux, this would be
sudo mkinitcpio -p linux

@Joao-Peterson
Copy link
Author

@butterdori thanks, i would never imagine that such options would be available and that it would involve an apple hid driver. By any chance, the mode 0 and 2 are any different in this case?

@butterdori
Copy link

butterdori commented Dec 2, 2023

I'm not sure, but 0 worked for my case. Also, just to add, the modprobe.d step was not sufficient for me to keep the setting persistent between reboots. I had to edit one more file. I cannot remember which right now.

Also, can the caps lock hold be used as a modifier for other keys, such as numbers to function keys? Using the fn key on the right can be tricky sometimes (such as ALT+F4).

@Joao-Peterson
Copy link
Author

@butterdori maybe you added a file entry for the modprobe file on /etc/mkinitcpio.conf?

As for the caps modifier, i belive caps lock remapping using keyd is the only way.

@alicercedigital
Copy link

vlw d+ poupou no mínimo 1 hora da minha vida rsrs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment