CMD & control keys swap in ubuntu

≯℡__Kan透↙ 提交于 2019-12-20 10:47:03

问题


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 solutions. Unfortunately none of them worked for me. I've tried using the standard "Keyboard layout", Xmodmap & whatever I came across. The closest I got is swaping them but disabling the arrow keys.

I'm using ubuntu 11.

Hope someone can help me. Thank you in advance.

Edit:

This is my xmodmap result:

    shift       Shift_L (0x32),  Shift_R (0x3e)
    lock        Caps_Lock (0x42)
    control     Control_L (0x25),  Control_R (0x69)
    mod1        Alt_L (0x40),  Alt_R (0x6c),  Meta_L (0xcd)
    mod2        Num_Lock (0x4d)
    mod3      
    mod4        Super_L (0x85),  Super_R (0x86),  Super_L (0xce),  Hyper_L (0xcf)
    mod5        ISO_Level3_Shift (0x5c),  Mode_switch (0xcb)

I want the control to be mod4 and vice versa. Thanks..


回答1:


EDIT: Just realized that this post was from six months ago. I doubt this will be any help, as you've probably (hopefully!) already gotten this solved, but, whatever.

Here's what you need to do:

Add the following to your ~/.Xmodmap file:

clear control
clear mod4

keycode 105 =
keycode 206 =

keycode 133 = Control_L NoSymbol Control_L
keycode 134 = Control_R NoSymbol Control_R
keycode 37 = Super_L NoSymbol Super_L

add control = Control_L
add control = Control_R
add mod4 = Super_L

To test this right now, just do xmodmap ~/.Xmodmap

Now, to have this happen every time at startup, add to the end of your (and/or create a new) ~/.xinitrc file the following:

xmodmap /home/your_username/.Xmodmap

Now restart / logout / restart X and you should be swell! Any trouble, please comment.




回答2:


Here's what I sometimes use to swap the control and caps-lock keys. It sounds like you've already tried similar things, but maybe you can hack this into something that will work.

To use this, you'd need to know xmodmap's name for the command key. The xev command, if you have it, might be useful for figuring this out.

#!/bin/sh

xmodmap - <<EOF
remove Lock = Caps_Lock
remove Control = Control_L
keysym Control_L = Caps_Lock
keysym Caps_Lock = Control_L
add Lock = Control_L
add Control = Control_L
EOF



回答3:


Depending of your desktop you can find easier or harder solutions for this.

If you have Gnome:

Just open Tweak tool, go to: Typing tab, and choose: Ctrl is mapped to Win keys in Alt/Win key behavior and you are done, is not perfect but works well.

If you have unity or other flavor you need to use Xmodmap, edit your ~/.Xmodmap with this:

remove control = Control_L
remove mod4 = Super_L Super_R

keysym Control_L = Super_L
keysym Super_L = Control_L
keysym Super_R = Control_L

add control = Control_L Control_R
add mod4 = Super_L Super_R

then add this next line to ~/.profile file and log in again.

xmodmap .Xmodmap 

I wrote this How To about this, maybe can help someone. https://chrissmejia.com/howto/swaps-the-ctrl-and-cmd-keys-in-ubuntu/




回答4:


This solution for change the keyboard permanently is better than other solution because for example if you change the language or reset your computer you must renew the Xmodmap command for update keyboard

but by this solution " Permanent xmodmap in Ubuntu 13.04 " your keyboard's map will change for ever.




回答5:


In Ubuntu 18 I ran gnome-tweaks then went to

Keyboard and Mouse - Keyboard - Overview Shortcut

3 buttons:

"Left Super", "Right Super" and "Additional Layout options"

Which I used to switch the default "Left Super" ('cmd' on a Mac) to "Right Super"

After doing that I was able to change VirtualBox's 'HostKey Combination' to 'Left WinKey' (although it's a MacBook keyboard)

VirtualBox Manager - File - Preferences - Input - Virtual Machine

Then switched the Ubuntu command key back to "Left Super", enabling Ubuntu to respond to the left command key in the Windows VM, rather than it being captured.




回答6:


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


来源:https://stackoverflow.com/questions/7099602/cmd-control-keys-swap-in-ubuntu

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!