CMD & control keys swap in ubuntu

后端 未结 6 1789
生来不讨喜
生来不讨喜 2021-02-02 02:09

I have an Apple keyboard with a cmd key which I\'m trying to swap with the control key.

From googleing the problem and searching across the forum I came with a several s

6条回答
  •  甜味超标
    2021-02-02 02:28

    I know some time has elapsed since this question was asked, but hopefully my answer can still help others or even the original author if they are still active and would like a better solution.

    You may find Kinto to be useful. It's a project I recently created, after a few years of tackling this problem a few different ways and I just now feel like it's solid enough to share.

    The Kinto installer simply uses python to do the initial install, after that it's just a systemd service, bash, xprop, setxkbmap and xkbcomp. As far as I am concerned it is the fastest and most native solution to this problem that you are going to find.

    https://github.com/rbreaves/kinto

    https://medium.com/@benreaves/kinto-a-mac-inspired-keyboard-mapping-for-linux-58f731817c0

    Here's a Gist as well, if you just want to see what is at the heart of it all, it will not alternate your keymap when needed though. The Gist also does not include custom xkb keymap files that setup macOS style cursors/word-wise manipulations that use Cmd and the arrow keys.

    https://gist.github.com/rbreaves/f4cf8a991eaeea893999964f5e83eebb

    gist content

    # 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 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!
    #
    

提交回复
热议问题