〖Linux〗使用命令行切换触摸板的状态on/off/toggle

时间:2021-01-31 02:58:24

最近发现在Ubuntu13.10中使用Fn+F9对触摸板的控制操作不灵了;

并且在黑夜、外置键盘时,按下这个组合键也很不方便,由此便想到使用命令行来切换触摸板状态;

脚本:~/bin/touchpadctrl

 #!/bin/bash -
#===============================================================================
#
# FILE: touchpadctrl
#
# USAGE: ./touchpadctrl
#
# DESCRIPTION:
#
# OPTIONS: ---
# REQUIREMENTS: ---
# BUGS: ---
# NOTES: ---
# AUTHOR: linkscue (scue), linkscue@gmail.com
# ORGANIZATION:
# CREATED: 2014年03月09日 12时57分34秒 CST
# REVISION: ---
#=============================================================================== # xinput --list ==> 获取TouchPad的id号(我的是13)
# xinput --list-props ==> 获取TouchPad的设备状态
# man xinput ==> 获取xinput的使用方法
on(){
#synclient TouchpadOff=
xinput set-prop 'Device Enabled'
echo -e "\e[0;36mtouchpad on.\e[0m" # cyan
exit
}
off(){
#synclient TouchpadOff=
xinput set-prop 'Device Enabled'
echo -e "\e[0;36mtouchpad off.\e[0m" # cyan
exit
} usage(){
echo -e "\e[0;31m==> Usage: $(basename $0) [ON/off/toggle].\e[0m" # red
exit
} getstate(){
echo $(xinput --list-props | grep Enable | awk -F: '{print $2}')
} toggle(){
echo -en "\e[0;31m==> toggle: \e[0m" # red
case $(getstate) in
"" ) on
;;
"" ) off
;;
esac
} # detect: help
if [[ ${} != "" ]]; then
case ${} in
"-h" | "--help" | "-help" )
usage
;;
esac
fi if [[ $# == ]]; then
# auto swtich
if [[ $(lsusb | grep 'Sunplus Innovation Technology') != "" ]]; then
off
else
toggle
fi
else
# manual
case ${} in
"of"|"off"|"OFF"|"Off") off
;;
"t"|"toggle"|"T"|"Toggle") toggle
;;
*) on
;;
esac
fi

使用举例:

  1. touchpadctrl

    -- 有外置鼠标时,自动off,否则toggle

  2. touchpadctrl on

    -- 启用触摸板

  3. touchpadctrl off

    -- 禁用触摸板

  4. touchpadctrl toggle

    -- 切换触摸板状态