使用命令行禁用所有Unity键盘快捷键
我想知道如何通过终端禁用所有键盘快捷键。 我知道您可以通过以下方式禁用它们:
系统设置>键盘>快捷方式
但我想通过终端禁用它们。 谁知道怎么做到这一点?
我不知道你为什么要这样做,我应该警告你,让快捷方式恢复可能会很复杂。 如果您真的想要这样做,下面的命令将禁用所有键盘快捷键。 通过Unity的GUI设置的那些以及您可能使用ccsm
设置的任何设置
A.禁用Unity键绑定
-
首先备份当前绑定,以便稍后重新启用它们
gsettings list-recursively org.gnome.desktop.wm.keybindings | perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' | while IFS=$'\t' read -r key val; do echo -e "$key\t$val"; done > old_settings
这将创建一个名为
old_settings
的文件,格式如下:schema key
value 例如:
org.gnome.desktop.wm.keybindings unmaximize
[' Down'] -
现在禁用快捷方式
gsettings list-recursively org.gnome.desktop.wm.keybindings | perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/' | while IFS=$'\t' read -r key val; do gsettings set $key ['']; done
说明
-
gsettings list-recursively org.gnome.desktop.wm.keybindings
:这列出了所有的键绑定及其当前值 -
perl -pe 's/(.*)\s*(\[.*?\])\s*$/$1\t$2\n/'
:这只是添加一个TAB字符(\t
)来分隔值钥匙。 需要执行此步骤才能在下一步中正确读取它们。 -
while IFS=$'\t' read -r key val
:遍历每一行并将密钥读入$k
,将其值读入$val
。$IFS=$'\t'
表示在选项卡上拆分,以便正确读取键和值。 -
gsettings set $key ['']
:这实际上将值设置为空白,有效地禁用了快捷方式。
请注意,您可能需要注销并重新登录才能使其生效。
-
-
获取(部分)快捷方式
while IFS=$'\t' read -r key val; do gsettings set "$key" "$val" done < old_settings
警告 :这可能不适用于所有设置,因为其中一些设置似乎在密钥名称中有一个额外的
@as
参数,我不知道如何处理那个。 正如我所说,这不是一个好主意。
B.禁用在ccsm
设置的自定义快捷方式
gsettings set org.gnome.settings-daemon.plugins.media-keys active false
这一次,让他们回来很容易。 你需要做的就是跑步
gsettings set org.gnome.settings-daemon.plugins.media-keys active true
我建立了@ terdon的答案并制作了一个脚本来做同样的事情 ,但是以一种更加用户友好的方式这样做。
你可以像这样使用它:
gnome-key-bindings --unset-all --except 'close|switch-applications'
由于我喜欢使用默认的键绑定Alt-F4和Alt-Tab(以及它们反向使用shift),这将删除除这些之外的所有键绑定。
它还有一个很好的帮助菜单:
List/disable/enable/set gnome-key-bindings gnome-key-bindings [-h | option] [value] Options --list Lists all the current keybindings --set=key Set a specific keybinding --unset=key Unsets a specific keybinding --unset-all Unsets all keybindings --except=REGEX Filter out keys matching REGEX from being unset --print-default Prints the default shortcuts per Ubuntu 18.04 Examples: Clearing all keys except a few: gnome-key-bindings --unset-all --except "close|switch-applications|switch-input-source|show-desktop" Setting a shortcut gnome-key-bindings --set=maximize "Up"
在自己的机器上使用它
curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/gnome-key-bindings -o gnome-key-bindings curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/easyoptions.sh -o easyoptions.sh curl -s https://raw.githubusercontent.com/fatso83/dotfiles/master/utils/scripts/easyoptions.rb -o easyoptions.rb chmod +x ./gnome-key-bindings sudo mv ./gnome-key-bindings easyoptions.* /usr/local/bin/