Created
October 10, 2022 08:53
-
-
Save acro5piano/33694b76daf01c98c84159fad2bd828e to your computer and use it in GitHub Desktop.
[linux] Run command on usb device plugged
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
# You need to run pip install pyudev before run this script | |
import subprocess | |
import pyudev | |
def main(): | |
context = pyudev.Context() | |
monitor = pyudev.Monitor.from_netlink(context) | |
monitor.filter_by(subsystem="usb") | |
monitor.start() | |
for device in iter(monitor.poll, None): | |
dt = device.get("DEVTYPE") | |
if dt == "usb_device": | |
subprocess.call(["xset", "r", "rate", "220", "60"]) | |
print("Keyboard rate set to 220, 60") | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment