Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import os
- import keyboard
- import time
- shutdown_time = 0
- shutting_down = False
- def mycallback( keyEvent ):
- global shutdown_time
- global shutting_down
- global home_pushed
- if keyEvent.event_type == keyboard.KEY_UP:
- print 'released'
- shutting_down = False #abort shutdown procedure
- elif keyEvent.scan_code == 142: #the "PC Power" button on the keyboard
- if shutting_down: #if they power button is being held in...
- print 'waiting for time to be up'
- if keyEvent.time - shutdown_time > 5: #...and more than 5s have elapsed...
- if keyboard.is_pressed( 'alt' ):
- print 'rebooting'
- os.system( 'sudo shutdown -r now' )
- elif keyboard.is_pressed( 'shift' ):
- print( 'logging out' )
- os.system( 'lxde-logout' )
- else:
- print 'shutting down'
- os.system( 'sudo shutdown -h now' ) #...shutdown!
- else: #if the button has just been pressed...
- print 'logging power button pressed time'
- shutdown_time = keyEvent.time #store the time it was initially pressed
- shutting_down = True #store that the button has been pressed and is now being held down
- elif keyEvent.scan_code == 172: #the "Home" button on the keyboard
- print 'showing desktop'
- keyboard.press( 'control' )
- keyboard.press( 'alt' )
- keyboard.press_and_release( 'd' )
- keyboard.release( 'control' )
- keyboard.release( 'alt' )
- elif keyEvent.scan_code == 164: #the 'pause/play' button aka F8
- print 'pausing/playing omxplayer'
- else:
- print keyEvent.scan_code
- print keyEvent.name
- print keyEvent.event_type
- print keyEvent.time
- keyboard.hook( mycallback )
- while True:
- time.sleep(10)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement