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

9 years 1 month ago

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

https://github.com/MyRobotLab/pyrobotlab/blob/master/service/Keyboard.py

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

i01.moveHand("left",0,0,0,0,0)

hope that helps you out!  happy robot-ing!

 

 

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

9 years 1 month ago

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?

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

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