Skip to content
Advertisement

How to detect if USB keyboard is plugged and unplugged

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 on how to do this?

Advertisement

Answer

udev (Linux device manager) is the one that polls hardware. When it detects some changes about devices, it executes the rule associated.

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.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement