Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Universal macOS keyboard layout for Linux - Applies to All Windows and Apple Keyboards
# permanent apple keyboard keyswap
echo "options hid_apple swap_opt_cmd=1" | sudo tee -a /etc/modprobe.d/hid_apple.conf
update-initramfs -u -k all
# Temporary & instant apple keyboard keyswap
echo '1' | sudo tee -a /sys/module/hid_apple/parameters/swap_opt_cmd
# Windows and Mac keyboards - GUI (Physical Alt is Ctrl, Physical Super is Alt, Physical Ctrl is Super)
setxkbmap -option;setxkbmap -option altwin:ctrl_alt_win
# Windows and Mac keyboards - Terminal Apps (Physical Alt is Super, Physical Super is Alt, Physical Ctrl is Ctrl)
setxkbmap -option;setxkbmap -option altwin:swap_alt_win
# If the hid_apple driver is not loaded for Apple keyboards, which can be found out
# by the lsmod command then the above setxkbmap commands will not work
# Use the following commands for Apple style keyboards without an hid_apple driver
#
# Note: this could also apply to hid_apple driver as well
# if this option is set to 0 inside swap_opt_cmd
#
lsmod | grep hid_apple
# Apple keyboard without hid_apple - GUI
setxkbmap -option;setxkbmap -option ctrl:swap_lwin_lctl,ctrl:swap_rwin_rctl
# Apple keyboard without hid_apple - Terminal
setxkbmap -option;setxkbmap -option altwin:alt_super_win
#
# If you want a systemd service and bash script to help toggle between
# GUI and Terminal applications then look at project Kinto.
# https://github.com/rbreaves/kinto
#
# Note: The above may not work for Chromebooks running Linux, please look
# at project Kinto for that.
#
# If anyone would like to contribute to the project then please do!
#
@Delvio
Copy link

Delvio commented Nov 6, 2021

man, I Do not understand this.... I just want to swap super for alt in my keyboard.... this should not be so hard

@rbreaves
Copy link
Author

rbreaves commented Nov 6, 2021

@Delvio

this is why my Kinto.sh project exists. This gist was just a very early & basic example of how to use setxkbmap to do the basic swap but not much else.

Stackoverflow was not initially very welcoming to accept my Kinto.sh project as an answer to the macOS key swap problem for Linux. At this point though my project is well known enough to not bother w/ posting myself, others do that fine, but I’ll leave these old gists up. They can be useful to someone but not really useful to most that just want a complete solution.

I can also be overly verbose - and for whatever reason Stackoverflow encouraged me to be overly verbose in explaining how Kinto.sh works.

@Delvio
Copy link

Delvio commented Nov 10, 2021

@rbreaves Can you please show me how can I just swap these two keys.... I mean I was able to find these files online but no instructions on how to set them up.

I would say that my biggest fear is to change something that would break my system after.

@rbreaves
Copy link
Author

rbreaves commented Nov 10, 2021

I’m not sure how it gets any clearer. If you’re not dealing w/ an apple keyboard where you can fix it via the hid driver then this. (Although it’d also work on the apple keyboard too. Just don’t apply the apple_hid specific driver key swap unless you’d prefer that method.. it’s documented up above too.)

# Windows and Mac keyboards - Terminal Apps (Physical Alt is Super, Physical Super is Alt, Physical Ctrl is Ctrl)
setxkbmap -option;setxkbmap -option altwin:swap_alt_win

Everything in my gist is well commented & a little bit of copying & pasting into your terminal would quickly reveal what’s going on (if my comments weren’t clear enough already) - but yes, make sure you know how to reset things before randomly applying things. Aka this resets setxkbmap. setxkbmap -option.

Pretty sure googling how to reset it though would have taken all of 5 seconds. The harder part of getting all of this info in one spot has already been done.

@rbreaves
Copy link
Author

rbreaves commented Nov 10, 2021

This gist was an early document & outline for what needed to happen for Kinto to be created to fully mimic Mac style keys. It is not intended to be a full solution for anything or anyone. Anyone can use it & look at it of course & it may be helpful to some.

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