高级键盘布局选项

高级键盘布局选项

我使用的是英语、俄语和亚美尼亚语键盘布局。当我尝试更改布局时,它会改变“en”->“am”->“ru”->“en”...我想使用Left Alt+Shift切换“en”和“am”,使用Right Alt+Shift切换“en”和“ru”。你能帮助我吗?

答案1

有很多捷径可供选择切换键盘布局,但没有一个符合您的要求。

无论如何,可以使用 bash 脚本和两个自定义快捷方式来完成。

首先,创建脚本,我们称之为change_layouts

#!/bin/bash
#script to switch between two keyboard layouts

if [ $# -ne 2 ];then
    echo "Usage: `basename $0` first_layout second_layout"
    echo "   ex: change_layouts us ru"
    exit
fi

first_layout=$1
second_layout=$2

if [ -z "$(ls -l /usr/share/X11/xkb/symbols | grep ^- | awk '{print $9}' | grep $first_layout)" ]; then
    echo "Error: Doesn't exists ant keyboard layout called '$first_layout'."
    exit
fi

if [ -z "$(ls -l /usr/share/X11/xkb/symbols | grep ^- | awk '{print $9}' | grep $second_layout)" ]; then
    echo "Error: Doesn't exists ant keyboard layout called '$second_layout'."
    exit
fi

if [ "$first_layout" = "$second_layout" ]; then
    echo "Error: The arguments (keyboard layouts) must to be different."
    exit
fi

current_layout=$(gsettings get org.gnome.libgnomekbd.keyboard layouts)

if [ "$current_layout" = "['$first_layout', '$second_layout']" ]; then
    gsettings set org.gnome.libgnomekbd.keyboard layouts "['$second_layout', '$first_layout']"
else 
    gsettings set org.gnome.libgnomekbd.keyboard layouts "['$first_layout', '$second_layout']"
fi

将脚本保存在您的~/bin目录中,并且不要忘记使其可执行:

chmod +x ~/bin/change_layouts

现在您可以在终端中测试该脚本。多次运行以查看其效果。

第二步,添加自定义快捷方式。转到系統設定键盘快捷方式自定义快捷方式并按照下图中的说明进行操作:

添加自定义快捷方式

相关内容