I have used the code I found here in the forum... it is very simple:

# create services
  python = Runtime.start("python", "Python")
  keyboard = Runtime.start("keyboard", "Keyboard")
   
  # non blocking event example
  keyboard.addKeyListener(python);
   
  def onKey(key):
  print "you pressed ", key
   
  # blocking example
  print "here waiting"
  keypress = keyboard.readKey()
  print "finally you pressed", keypress, "!"

But I can get neither the blocking of non-blocking code to work.  It runs and just sits at 
keypress=keybaod.readkey()
and never sees my keystrokes on my PC keyboard.  Does anyone have an an idea for me?

When I have the MRL GUI up, the top of the window says 
myrobotlab - GUI 1.0.119

Thanks,

Bruce

GroG

8 years 5 months ago

Hello Bruce and Welcome.
The keyboard service requires you to keep focus in the button which says "Click here for keyboard control".
When you do that you'll get keyboard input.  When the button loses focus, you will no longer get keyboard input.

The Joystick service can also provide keyboard input, if the keyboard is selected as an input device ...  I believe no button is required to maintain focus - but the application as a whole must be in focus.

Cheers,

GroG

Grog,

I was just writing you a note to tell you I tried what you said and it did not work.  I was going back to MRL to get the exact wording of the command you told me to use, and guess what... now it works.  

I see what it is now... it only accepts a new keystroke if the tab for the Keyboard Service is in focus when I hit a key.  In this case, the key does get to Python where it prints out correctly.  But if I go to the Python Tab, nothing.  I hit a key in the lower pane, Python Tab,  and the keystroke prints out but it does not get serviced by the Python code.  When I switch back to the Keyboard tab, I see the keystroke logged and Python services it.

Bruce

 

you can right click on the keyboard tab - and undock - so you can watch the Python output & still keep focus with the keyboard button - and what cause & effect..