Skip to content

Instantly share code, notes, and snippets.

@acro5piano
Created October 10, 2022 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save acro5piano/33694b76daf01c98c84159fad2bd828e to your computer and use it in GitHub Desktop.
Save acro5piano/33694b76daf01c98c84159fad2bd828e to your computer and use it in GitHub Desktop.
[linux] Run command on usb device plugged
#!/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