Keyboard in python

I'm sure I should be able to work this out, I want Inmoov to run different functions depending on the key pressed on the computer keyboard. I can start a keyboard in python, but can't work out how to respond to  key events.

kwatters's picture

examples are good...

Have a look at the python code at the following url.  It might help you get what you want working.

Basically, it defines a callback method called "onKey"   that should be invoked when you press a key.  In that method you can check which key it is and potenitally do something with the inmoov service like


hope that helps you out!  happy robot-ing!



bensonofjohn's picture

Thanks KevinI had tried this

Many thanks Kevin

I had tried this code before and thought it did't work. Now red faced as I realised I was looking looking at the Java tab output not the Pyhon tab so assumed the code didn't work.

Everything is working beautifully now.

balaw1's picture

I could use some help on getting keyboard working

I am also creating some debug code via the keyboard.  I want to, for example" invoke my open_hand routime when I input a 2.  I ran the code in this thread, I used only the "blocking" example.  It worked one time, then never again.  And the "non-blocking" example never worked.  

in the "blocking" it gets to the line:

keypress = keyboard.readKey()

it sits there and waits, but never returns a keystroke when i hit a key on the keyboard.

Any clues?

Kakadu31's picture

I think i got the same or a

I think i got the same or a similar problem, the test-script is getting all the keys for me flawless, but as soon as i want to do something with the received characters like with a simple   if keypress == x:   print "test"
or invoking a method, the script seems to freeze after the first character and doesnt react anymore

bensonofjohn's picture

What happens if you try the

What happens if you try the script below? This works fine for me.
keyboard = Runtime.start("keyboard", "Keyboard")
def onKey(key):
    if(key == 'G'):
        print("Hello G")
        print("Not G")
Kakadu31's picture

Ah there it is!  I somehow

Ah there it is!  I somehow didnt put the G in '..'  and therefore the service crashed!  
A bit embarassing to chew  so long on an error like this..
Thx mate!