import mouse
import time
import os
while True:
before_sleep = mouse.get_position()
time.sleep(600)#depends on you
after_sleep = mouse.get_position()
if before_sleep == after_sleep:
os.system("shutdown /s /t 1")
#you can make your own detection to find if user is using keyboard