What I tried:
- crontab -e
- creating a desktop entry at /home/pi/.config/autostart
- edit /etc/rc.local
My python script:
import os
from gpiozero import Button
from time import sleep
from pynput.keyboard import Key, Controller
k = Controller()
shutdown = Button(2)
reld = Button(3)
while True:
if shutdown.is_pressed:
print("shutdown")
os.system("sudo shutdown -h now")
if reld.is_pressed:
print("reload")
k.press(Key.ctrl)
k.press(Key.f5)
k.release(Key.f5)
k.release(Key.ctrl)
sleep(0.2)
I tried to start the script with this command which works fine in the therminal:
python3 /home/pi/Documents/script.py