Linux:如何检测USB键盘是否已插入和拔出 [英] Linux : How to detect if USB keyboard is plugged and unplugged
问题描述
当从PC上拔下USB键盘时,是否有任何守护程序/工具会触发一些信号/事件?我需要在程序中知道何时插入和拔出USB键盘.任何想法如何做到这一点?
Is there any daemon/tool which will trigger some signal/event when usb keyboard is plugged and unplugged from pc ? I need to know in my program when usb keyboard is plugged and unplugged. Any ideas how to do this ?
关于,莱文
推荐答案
udev(Linux设备管理器)是轮询硬件的一种.当它检测到有关设备的某些更改时,将执行关联的规则.
udev (Linux device manager) is the one that polls hardware. When it detects some changes about devices, it executes the rule associated.
您应该在udev中添加一个规则,以告知您的程序有关插入USB键盘的信息.您可以在此处找到有关udev规则的文档,或在/etc/udev/rules中查看文件.d/
或/lib/udev/rules.d/
可以找到许多示例.
You should add a rule to udev, in order to inform your program about insertion of removal of USB keyboard. You can find documentation about udev rules here, or Look at files in /etc/udev/rules.d/
or /lib/udev/rules.d/
to find many examples.
这篇关于Linux:如何检测USB键盘是否已插入和拔出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!