0

Im currently learning to program and a friend asked me if i can write a program to shut down a pc. I used the os and keyboard module and my code is the following

import keyboard
import os

keyboard.add_hotkey('s', lambda: os.system('shutdown -s'))

The program works but he asked me if i could run it in the background is there a module for that

JohanL
  • 6,671
  • 1
  • 12
  • 26

1 Answers1

0

That's not related to your python program.
to run your program in background, try
./program.py &
or
nohup python program.py
for windows, this will be helpful: Running Python Script as a Windows background process
----------------------------------
check Detecting a keypress in python while in the background either.

Jafari MM
  • 57
  • 1
  • 7
  • 1
    But then there will be no controlling terminal receiving the input, and it won't work for capturing the keys pressed. – JohanL Oct 12 '18 at 04:50