Python key pressed without Tk
Question: I use a Raspberry Pi via SSH from my Windows 7 and I build a robot. If you
press an arrow, it will move. I detect the key with TkInter module, but it
needs a graphic environment. So if I am only in an SSH terminal, it can't run.
Is there some module which can detect keys and doesn't need a window?


Answer: i have not tried it, but a quick search has shown up this:  
[example](http://jeffhoogland.blogspot.co.uk/2014/10/pyhook-for-linux-with-
pyxhook.html)  
[github source](https://github.com/JeffHoogland/pyxhook)

which is essentially a linux implementation of pyhook (windows only)

so to use it:

    
    
    import pyxhook
    import time
    
    #This function is called every time a key is presssed
    def kbevent( event ):
        #print key info
        print event
    
        #If the ascii value matches spacebar, terminate the while loop
        if event.Ascii == 32:
            global running
            running = False
    
    #Create hookmanager
    hookman = pyxhook.HookManager()
    #Define our callback to fire when a key is pressed down
    hookman.KeyDown = kbevent
    #Hook the keyboard
    hookman.HookKeyboard()
    #Start our listener
    hookman.start()
    
    #Create a loop to keep the application running
    running = True
    while running:
        time.sleep(0.1)
    
    #Close the listener when we are done
    hookman.cancel()
    

