为了在适当的情况下进行Spacebar操作Ctrl,目前的 GitHub 页面xcape
说明如下:
# Map an unused modifier's keysym to the spacebar's keycode and make it a
# control modifier. It needs to be an existing key so that emacs won't
# spazz out when you press it. Hyper_L is a good candidate.
spare_modifier="Hyper_L"
xmodmap -e "keycode 65 = $spare_modifier"
xmodmap -e "remove mod4 = $spare_modifier" # hyper_l is mod4 by default
xmodmap -e "add Control = $spare_modifier"
# Map space to an unused keycode (to keep it around for xcape to
# use).
xmodmap -e "keycode any = space"
# Finally use xcape to cause the space bar to generate a space when tapped.
xcape -e "$spare_modifier=space"
如何用xkb
而不是实现这一目标xmodmap
?
答案1
用Hyper_R
代替Hyper_L
,它是这样的:
内容~/.config/xkb/keycodes/my-keycodes
:
xkb_keycodes "xcape-special" {
<HYPR> = 65;
<SPCE> = 207;
};
注意:是我的机器上加载的键码表中207
(虚拟)键的默认键码。Hyper_R
内容~/.config/xkb/symbols/my-symbols
:
xkb_symbols "xcape-special" {
key <HYPR> { [ Hyper_R ] };
modifier_map Control { <HYPR> };
};
摘录自~/.xinitrc
:
XKB_DIR="$HOME/.config/xkb"
XKB_SYMBOL_FILE="my-symbols"
XKB_KEYCODE_FILE="my-keycodes"
setxkbmap -layout "us+$XKB_SYMBOL_FILE(xcape-special)" \
-keycodes "evdev+$XKB_KEYCODE_FILE(xcape-special)" \
-option "" -print \
| xkbcomp -I"$XKB_DIR" - "${DISPLAY%%.*}" >/dev/null 2>&1
xcape -e "Hyper_R=space"
这不是唯一的配置方法xkb
。配置可能可以通过一次调用从单个文件加载xkbcomp
。的子目录~/.config/xkb/
仅遵循 的结构/usr/share/X11/xkb/
。这... -print | xkbcomp ...
部分有点复杂但很灵活。目前我无法尝试更简单的设置。