|
1234567891011121314151617181920212223242526272829303132 |
- #!/usr/bin/env python
-
- import subprocess
-
- keyboard = "AT Translated Set 2 keyboard"
- battery = "/sys/class/power_supply/BAT0"
- device = "2"
- faces = "faces"
- key = "36"
-
- bat = False
- if battery is not None:
- with open(f"{battery}/status", "r") as f:
- s = f.read().strip()
- if s == "Discharging" or s == "Unknown":
- bat = True
-
- proc = subprocess.Popen(
- f"./facematcher.py match --wait --delay 500 --device {device} {faces}/$USER/*",
- stdin=subprocess.PIPE, shell=True)
-
- if bat:
- print(f"On battery, so waiting for {key}")
- subprocess.check_output(
- f"xinput test '{keyboard}' | grep --line-buffered 'key press {key}' | " +
- f"while read -r line; do exit; done",
- shell=True)
- print(f"Got {key}.")
-
- proc.stdin.write(b"hello\n")
- proc.stdin.flush()
- exit(proc.wait())
|