大多数其他解决方案在会话启动时(或更早)加载
xmodmap
,但是当您插入新的键盘(或切换KVM开关)时,您的设置会被清除。这里有一个解决方案,在您插入USB设备后重新安装
xmodmap
。自从Linux引入所有Alt/Meta混淆(大约在2006年)以来,我一直在使用它。
! ~/.Xmodmap file
!
! Part 1 (since about 2006)
! Avoid BadValue (TODO: debug why we get BadValue otherwise)
clear mod1
clear mod4
! Actually, my keyboard doesn't have 0xcc/0xcd keys, thank you...
keycode 0xcc = NoSymbol
keycode 0xcd = NoSymbol
! mod3 is Alt. I'm sure this is documented somewhere.
! It works that way in every program!
add mod3 = Alt_L
add mod3 = Alt_R
! In addition to Alt keys, my keyboard has ... drumroll ... *Windows* keys!
! These are *Meta* keys. Say, in Windows web browsers.
! Don't take my word for it, hit F12 and type:
! onkeydown = function(e){console.log(e);}
! And, um, Alt is already taken, so obviously Meta = Windows key.
! Also Windows keys = Meta in some FreeBSD distros out of the box.
! Is Windows keys = Meta not clear to someone, or is someone just being annoying
! with all this "Alt = Meta" garbage?
keycode 0x85 = Meta_L
keycode 0x86 = Meta_R
! No, mod1 is not Alt!
! In every program, mod1 is actually meta!
add mod1 = Meta_L
add mod1 = Meta_R
remove mod1 = Alt_L
remove mod1 = Alt_R
! Part 2 (since about 2015)
! What is going on?? USB thinks it can just wipe my xmodmap???
!
! 1. Locate xkb rulefile using
!
! udevadm control --log-priority=info
!
!
! It will be something like
!
! /lib/udev/rules.d/64-xorg-xkb.rules
!
!
! 2. Edit /lib/udev/rules.d/64-xorg-xkb.rules. Add:
!
! RUN += "/big/usb_fix.sh"
!
! and do:
!
! udevadm control --reload-rules
!
! note: using /big is intentional... on new Ubuntus, the system dies
! with "a start job is running..." in disk mounting. So we prevent this
! script from running ig /big is not mounted yet.
!
!
! 3. Create the /big/usb_fix.sh script:
!
! #!/bin/sh
! echo "xmodmap ~/.Xmodmap" >> /usr/local/usb_fix.log
!
! and make it executable.
!
!
! 4.
! mkfifo /usr/local/usb_fix.log
!
!
! 5.
! Create a script (e.g. named ~/bin/usb_fix_client)
!
! #!/bin/sh
! yes 'cat /usr/local/usb_fix.log | sh' | sh
!
! and put this in your .xinitrc.
! Part 3 (since about 2018)
!
! Every now and then, apt-get can overwrite the xorg-xkb-rules?
! solution for now is turn off automatic updates.
如果你已经正确设置了,xmodmap应该显示如下内容:
shift Shift_L (0x32), Shift_R (0x3e)
lock Caps_Lock (0x42)
control Control_L (0x25), Control_R (0x69)
mod1 Meta_L (0x85), Meta_R (0x86)
mod2 Num_Lock (0x4d)
mod3 Alt_L (0x40), Alt_R (0x6c)
mod4
mod5 ISO_Level3_Shift (0x5c), Mode_switch (0xcb)
而且,你的meta和alt键现在可以正常工作了!
如果很难找到并关闭一直覆盖你的USB规则的软件(对我来说,有些软件每年会破坏它大约两次),那么只需添加一个RC脚本来复制你的USB规则回来。此外,你还可以将改进后的规则复制到一个数字更大的文件中,以便在未来覆盖其他可能破坏你的xmodmap的变化。
未修改
Shift
AltGr*
Shift+AltGr
。但是左Alt
和超级键
呢? - Farzherxkb
中的键盘映射来实现。除了晦涩难懂之外,这种方法还存在一个问题,就是当xkb
更新时,你的自定义映射会被删除。 - Mateus Araújoxkbcomp $DISPLAY myFile
命令。 - phil294$ ls -R /usr/share/X11/xkb/symbols/ | grep -i en
给出了这个结果:parens
- Johanevdev
的解决方案持续有效,详见https://askubuntu.com/a/1161870/835198。 - Mario