简体   繁体   中英

Get event for new USB keyboard connected on Linux

Is there any event I can listen to when a new keyboard attaches in Python? I'd like to disable the internal laptop keyboard and run xmodmap for the new keyboard. My only idea right now is polling xinput list and then grep USB. Is there a better way to do it?

It's years since I've done anything like this, so I don't have any code examples for you, but I think for the problem you're looking at, you should consider a udev rule.

This looks like a good resource for udev: https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux

If I remember correctly (It's a VERY long time since I made a custom udev rule; I might NOT remember correctly), one thing you could do is execute a python script when something's plugged in, and that something happens to be a USB keyboard.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM