Skip to content

Instantly share code, notes, and snippets.

@geerlingguy
Last active October 17, 2021 02:19
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 geerlingguy/e63ba36b178b62ce4a26ab90ea154946 to your computer and use it in GitHub Desktop.
Save geerlingguy/e63ba36b178b62ce4a26ab90ea154946 to your computer and use it in GitHub Desktop.
Python 3 version of Null 2 systembuttons.py
#!/usr/bin/python3
# Shutdown and volume control
import keyboard
import time
import os
INITIAL_VOLUME = "25%"
def shutdown():
os.system("sudo shutdown -h now")
def volumeUp():
os.system("amixer sset -q 'Master' 5%+")
def volumeDown():
os.system("amixer sset -q 'Master' 5%-")
# Initialize volume at INITIAL_VOLUME.
os.system("amixer sset -q 'Master' " + INITIAL_VOLUME)
keyboard.add_hotkey('y+s', callback=volumeUp)
keyboard.add_hotkey('y+a', callback=volumeDown)
keyboard.add_hotkey('y+left alt', callback=shutdown)
keyboard.wait()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment