筆電上的觸控板雖然方便,但外接滑鼠時反而容易誤觸。多數機型有快捷鍵可以開關,萬一失效(或桌面環境沒綁定),改用 xinput 搭配一支小腳本,同樣能一鍵搞定。以下示範 CentOS 6.4 的做法。
xinput 由這個套件提供:
rpm -qa xorg-x11-apps
若沒有輸出,安裝它:
yum install xorg-x11-apps
xinput list
輸出會列出 Virtual core pointer、Virtual core keyboard 等 master 裝置,以及底下掛的 slave 裝置,每個都有一組 id,後續操作全靠這個編號。
觸控板名稱因廠牌而異,但通常是一個 PS/2 裝置,名稱裡會出現 PS/2 或 touchpad 字樣。若實在認不出來,可以用排除法:逐一停用 Virtual core pointer 底下每個裝置,滑一下觸控板看是否失效。
xinput --set-prop 裝置id "Device Enabled" 0
停用後觸控板不動,就代表找到目標;接著把其他非觸控板裝置用同樣指令、參數改為 1 恢復啟用即可。
新增 touchpad.sh:
vim touchpad.sh
內容如下(把 13 換成你實際查到的 id):
#!/bin/bash
if [ "$1" = "on" ] || [ "$1" = "1" ]
then
xinput --set-prop 13 "Device Enabled" 1
echo "open"
elif [ "$1" = "off" ] || [ "$1" = "0" ]
then
xinput --set-prop 13 "Device Enabled" 0
echo "close"
else
echo "請輸入正確的參數:on/off、0/1。"
echo "開啟觸控板:sh touchpad on 或 sh touchpad 1。"
echo "關閉觸控板:sh touchpad off 或 sh touchpad 0。"
fi
之後只要執行 sh touchpad off 就能關閉,sh touchpad on 再打開。做法比快捷鍵多繞一點路,但當快捷鍵失效時,這招往往就是最後的救命繩。