根文件系统中,一般用mdev来管理设备,不像udev方便,有时候在执行rcS脚本的时候因为,太快,有些设备比如鼠标还没在/dev/input中生成设备文件,最好使用前用mdev -s扫描并等待几秒钟,然后就可以在input中看到event*的设备文件了,通过程序或者evtest工具可以看到每个event文件对应的是什么设备,这玩意研究了好几天,尤其鼠标设备,一开始以为是/dev/input/mice,实际并不能用这个设备文件给qt用,必须event开头的,但是evtest工具枚举并没有看到mouse字样的设备,只看到了keyboard,后来发现是mdev -s再执行一次等待几秒就能看到了,也许是设备初始化较晚的原因:
bash
echo "scan keyboard mouse device..."
mdev -s
sleep 2
devices=$(ls /dev/input/ | grep 'event')
kbdevice=""
micedevice=""
for device in $devices; do
device_path="/dev/input/$device"
output=$(timeout 0.5 evtest "$device_path" 2>/dev/null)
if echo "$output" | grep -iq 'keyboard'; then
echo "Found keyboard device: $device_path"
kbdevice=$device
elif echo "$output" | grep -iqE 'mouse|touchpad'; then
echo "Found mouse device: $device_path"
micedevice=$device
fi
if [ "$kbdevice" != "" ] && [ "$micedevice" != "" ]; then
break
fi
done
export QT_QPA_PLATFORM_PLUGIN_PATH=/usr/lib/x86_64-linux-gnu/qt5/plugins
export QT_QPA_GENERIC_PLUGINS=evdevmouse,evdevkeyboard
if [ "$micedevice" != "" ];then
export QT_QPA_EVDEV_MOUSE_PARAMETERS=/dev/input/$micedevice
fi
if [ "$kbdevice" != "" ];then
export QT_QPA_EVDEV_KEYBOARD_PARAMETERS=/dev/input/$kbdevice
fi