在目前这个笔记本上装了 Ubuntu 11.04,多次遇见了触摸板干扰鼠标的情况。一般是鼠标按键失效,移动还可以。一开始我还以为鼠标坏了呢,心想正好有机会换个无线的,后来发现是触摸板的问题,只需按一下触摸板左键即可恢复正常。刚才又出现这种情况,让我误以为是 X 出毛病了,切换到另一个 tty,等 kill 掉 Firefox 的时候想明白了,按了一下触摸板。以前都是想禁用的时候输入命令 synclient TouchPadOff=1
,不过这次是一定要彻底解决这个问题。
这里有个脚本 mouseSwitcher.sh,内容如下:
#!/bin/bash
#
# Toggle touchpad on and off
#
# Author: Heath Thompson
# Email: [email protected]
#
# For startup wait for desktop to load first.
while true
do
if ps -A | grep gnome-panel > /dev/null;
then
echo 'X loaded'
break;
else
echo 'X not loaded, waiting...'
sleep 5
fi
done
#
# Check to see if appletouch is running
# if lsmod | grep appletouch > /dev/null;
# then
# echo " * Appletouch enabled";
# else
# echo " * Appletouch either not working or not installed"
# killall mouseSwitcher
# fi
while true
do
# 'xinput list' will list all input devices x detects
# I could reference my usb mouse by ID but I'm afraid that if I plug
# another device in before my mouse, it might not have the same ID each
# time. So using the device name makes it relatively fail-safe.
if xinput list 'Microsoft Microsoft? 2.4GHz Transceiver v5.0';
then
# Found my usb wireless mouse
# Disable everything on the Touchpad and turn it off
synclient TouchpadOff=1 MaxTapTime=0 ClickFinger1=0 ClickFinger2=0 ClickFinger3=0;
# Ends all syndaemon capturing which may have been used to monitor the touchpad/keyboard activity
killall syndaemon
else
# My usb wireless mouse isn't present we need the touchpad
# Reenable Touchpad and configure pad-clicks
# RTCornerButton is the Right Top Corner on the touchpad
# The value 3 maps it as the right click button
# RBCornerButton is the Right Bottom Corner on the touchpad
# The value 2 maps it as the middle click button
synclient TouchpadOff=0 MaxTapTime=150 ClickFinger1=1 ClickFinger2=2 ClickFinger3=3 RTCornerButton=3 RBCornerButton=2;
# Forces break of touchpad functions while typing if the touchpad is enabled.
# Adds a 3 second interval following keyboard use which helps to prevent the
# mouse from jumping while typing & resting hands on restpad or the touchpad
syndaemon -i 3 -d;
fi
# wait 2 seconds and poll the mouse state again
sleep 2
done
sleep 15
但是在我系统里,xinput list
用设备名字做参数就是找不出来。以下是 xinput list
的结果:
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ PS/2 Mouse id=12 [slave pointer (2)]
⎜ ↳ AlpsPS/2 ALPS GlidePoint id=13 [slave pointer (2)]
⎜ ↳ Microsoft Microsoft Basic Optical Mouse v2.0 id=10 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ Video Bus id=7 [slave keyboard (3)]
↳ Power Button id=8 [slave keyboard (3)]
↳ Sleep Button id=9 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=11 [slave keyboard (3)]
↳ Ideapad extra buttons id=14 [slave keyboard (3)]
但是 xinput list 'Microsoft Microsoft Basic Optical Mouse v2.0'
就找不到:
unable to find device Microsoft Microsoft Basic Optical Mouse v2.0
好像也有别人遇到这样的问题,看这个 bug. 不过换一种思路即可解决,根据我的鼠标的名字,把那一行换成这样:
if [[ "$(xinput list | grep -F "Optical Mouse")" ]]
还有个问题,如果找不到鼠标,该脚本会不停地创建 syndaemon 进程,过一会机器就几乎死掉。所以在创建之前应该先检查一下是不是已经有这个进程了:
if [[ -z "$(pidof syndaemon)" ]]
then
syndaemon -i 3 -d;
fi
执行该脚本,把鼠标插拔测试以下,可以用了。于是 chmod +x mouseSwitcher.sh
,然后在 System Preferences 的 Startup Applications 里添加上,以后就不用操心了。
修改后的完整脚本如下:
#!/bin/bash
#
# Toggle touchpad on and off
#
# Author: Heath Thompson
# Email: [email protected]
#
# For startup wait for desktop to load first.
while true
do
if ps -A | grep gnome-panel > /dev/null;
then
echo 'X loaded'
break;
else
echo 'X not loaded, waiting...'
sleep 5
fi
done
#
# Check to see if appletouch is running
# if lsmod | grep appletouch > /dev/null;
# then
# echo " * Appletouch enabled";
# else
# echo " * Appletouch either not working or not installed"
# killall mouseSwitcher
# fi
while true
do
# 'xinput list' will list all input devices x detects
# I could reference my usb mouse by ID but I'm afraid that if I plug
# another device in before my mouse, it might not have the same ID each
# time. So using the device name makes it relatively fail-safe.
if [[ "$(xinput list | grep -F "Optical Mouse")" ]]
then
# Found my usb wireless mouse
# Disable everything on the Touchpad and turn it off
synclient TouchpadOff=1 MaxTapTime=0 ClickFinger1=0 ClickFinger2=0 ClickFinger3=0;
# Ends all syndaemon capturing which may have been used to monitor the touchpad/keyboard activity
killall syndaemon &> /dev/null
else
# My usb wireless mouse isn't present we need the touchpad
# Reenable Touchpad and configure pad-clicks
# RTCornerButton is the Right Top Corner on the touchpad
# The value 3 maps it as the right click button
# RBCornerButton is the Right Bottom Corner on the touchpad
# The value 2 maps it as the middle click button
synclient TouchpadOff=0 MaxTapTime=150 ClickFinger1=1 ClickFinger2=2 ClickFinger3=3 RTCornerButton=3 RBCornerButton=2;
# Forces break of touchpad functions while typing if the touchpad is enabled.
# Adds a 3 second interval following keyboard use which helps to prevent the
# mouse from jumping while typing & resting hands on restpad or the touchpad
if [[ -z "$(pidof syndaemon)" ]]
then
syndaemon -i 3 -d;
fi
fi
# wait 2 seconds and poll the mouse state again
sleep 2
done
sleep 15
Leave a Reply