Detect Keyboard event
 Software and Programming Related   Started by AndreasW   2017-01-19 13:46:17 -05:00   Comments: 7    Viewed: 201

  1. AndreasW
    AndreasW Member
    Dear programmers,

    I'm looking for a way to detect keyboard events, e.g a keypress from a python program started via the Pistorms browser. My goal is to interact with the running program via a wireless keyboard attached to the Pi. Using the Scratch-interface, this works fine. But wirh Python alone, I can't get it working, as e.g. curses does not work without a terminal.

    What could you suggest me to do?

    Andreas
    AndreasW, 2017-01-19 13:46:17 -05:00
  2. Mindsensors Support
    Mindsensors Support Member Richmond
    Does your keyboard have a USB dongle that connects to Pi?
    Mindsensors Support, 2017-01-19 13:56:02 -05:00
  3. AndreasW
    AndreasW Member
    It does. It's automatically detected and works fine on the terminal and in the gui. I can use it with pistorms via the scratch interface to detect keypress events or with python scripts started from the terminal (via curses). However, i found no way to use curses or similar in a .py program started from pistorms browser. What do you suggest?
    AndreasW, 2017-01-21 09:33:54 -05:00
  4. AndreasW
    AndreasW Member
    To be a bit more precise: The problem is not the wireless keyboard. I just can't figure out how ro detect keypress events using a .py started from the PiStorms browser (i.e. the small screen). Question 1: How do you do that?

    Maybe my problem is more general. Question 2: What exactly happens when starting a .py from the PiStorms browser, i.e. how does the browser call the .py?
    AndreasW, 2017-01-23 12:47:38 -05:00
  5. Mindsensors Support
    Mindsensors Support Member Richmond
    PiStorms Browser is started in /etc/init script (it runs in background - where TTY is not associated).
    As a result any programs started from Browser have no associated TTY.
    Do you have a monitor/keyboard connected? If so, you can start the PiStorms Browser from a Terminal window (and not run it in background).
    that way any program that is started by the Browser will receive input from that terminal.

    Alternately, may be you can access the USB device directly and monitor it for any input traffic?
    Mindsensors Support, 2017-01-23 17:29:43 -05:00
  6. AndreasW
    AndreasW Member
    Thanks for the info where to find the browser. That may help.

    >Alternately, may be you can access the USB device directly and monitor it for any input traffic?
    This would be great! How could I access the USB keyboard directly to monitor the traffic? Do you have an idea?
    I'd really wonder if you or others don't make use of a keyboard to interact with robots. There has to be some solution... :)
    AndreasW, 2017-01-25 13:04:24 -05:00
  7. Mindsensors Support
    Mindsensors Support Member Richmond
    We have not done this, but you should be able to find methods to read from USB device directly - google it.
    as a tip, run command 'lsusb' to see what your device is enumerated as, and use that info to know more about it.
    Generally it will also be listed Linux devices (in /dev folder), you may be able to read from that device entry directly.
    Mindsensors Support, 2017-01-26 10:49:31 -05:00
  8. (You must log in or sign up to post here)

Log in | Sign up
Tems & Conditions!
Help!