tkinter - Python key pressed without Tk -
i use raspberry pi via ssh windows 7 , build robot. if press arrow, move. detect key tkinter module, needs graphic environment. if in ssh terminal, can't run. there module can detect keys , doesn't need window?
i have not tried it, quick search has shown this:
example
github source
which linux implementation of pyhook (windows only)
so use it:
import pyxhook import time #this function called every time key presssed def kbevent( event ): #print key info print event #if ascii value matches spacebar, terminate while loop if event.ascii == 32: global running running = false #create hookmanager hookman = pyxhook.hookmanager() #define our callback fire when key pressed down hookman.keydown = kbevent #hook keyboard hookman.hookkeyboard() #start our listener hookman.start() #create loop keep application running running = true while running: time.sleep(0.1) #close listener when done hookman.cancel()
Comments
Post a Comment