简体   繁体   English

获取连接在 Linux 上的新 USB 键盘的事件

[英]Get event for new USB keyboard connected on Linux

Is there any event I can listen to when a new keyboard attaches in Python?当 Python 中连接新键盘时,我可以听到任何事件吗? I'd like to disable the internal laptop keyboard and run xmodmap for the new keyboard.我想禁用内部笔记本电脑键盘并为新键盘运行 xmodmap。 My only idea right now is polling xinput list and then grep USB.我现在唯一的想法是轮询xinput list ,然后轮询 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.自从我做过这样的事情以来已经有好几年了,所以我没有任何代码示例给你,但我认为对于你正在查看的问题,你应该考虑一个 udev 规则。

This looks like a good resource for udev: https://linuxconfig.org/tutorial-on-how-to-write-basic-udev-rules-in-linux这看起来像是 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.如果我没记错的话(自从我制定了自定义 udev 规则以来已经很长时间了;我可能记错了),您可以做的一件事是在插入某些东西时执行 python 脚本,而这恰好是 USB 键盘。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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