Enable pynput keylistener to work as service

This commit is contained in:
Leone, Mark A [LGS] 2025-07-12 23:20:03 -04:00
parent ce88168e2e
commit 6f178c6874
5 changed files with 15 additions and 8 deletions

View file

@ -1,6 +1,15 @@
#!/bin/bash
args="$*"
chmod +x run.sh
# If first arg is of form :n it will set DISPLAY to :n. Default is :0
dsp_prefix=:
dsp=:0
# if [[ -n "${1+x}" ]]; then
if [[ $1 == $dsp_prefix* ]]; then
dsp="$1"
shift
fi
# fi
args="$*"
rm -f fwledmonitor.service || true
sed -i "s#led_system_monitor.py.*\$#led_system_monitor.py ${args}#" run.sh
cat <<EOF >>./fwledmonitor.service
@ -9,6 +18,7 @@ Description=Framework 16 LED System Monitor
After=network.service
[Service]
Environment=DISPLAY=${dsp}
Type=simple
Restart=always
WorkingDirectory=$PWD

View file

@ -16,7 +16,6 @@ from monitors import CPUMonitor, MemoryMonitor, BatteryMonitor, DiskMonitor, Net
# External Dependencies
import numpy as np
from pynput.keyboard import Key, Listener
import evdev
from serial.tools import list_ports
@ -35,9 +34,7 @@ def discover_led_devices():
return sorted(locations, key = lambda x: re.sub('^\d+\-\d+\.', '', x[0]))
except Exception as e:
print(f"An Exception occured while tring to locate LED Matrix devices. {e}")
device = evdev.InputDevice('/dev/input/event7')
def main(args):
led_devices = discover_led_devices()
if not len(led_devices):

4
run.sh Normal file → Executable file
View file

@ -1,3 +1,3 @@
sudo apt install -y python3-numpy python3-psutil python3-serial python3-evdev
python3 ./led_system_monitor.py
xhost +local:root
python3 ./led_system_monitor.py

View file

@ -0,0 +1 @@
[[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0,1],[0,1,0,1,0,1,0,1,0],[1,0,1,0,1,0,1,0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