Keypress Input

Michael Torrie torriem at gmail.com
Sun Jun 7 00:31:22 EDT 2015


On 06/06/2015 12:28 PM, John McKenzie wrote:
> 
>  Laura and Gary, thank you for your replies. I have three physical 
> buttons connected to a Kade device emulating a keyboard. These buttons 
> control an LED light strip. So there is no screen, so a GUI did not cross 
> my mind. I thought it made sense as it is easily done by other scripting 
> languages. Thank you both for pointing my in the right direction.

I assume this is on a Linux box of some kind, perhaps an embedded computer?

Actually you can indeed do what you want from a command-line program.
The curses module supports a function called "getch" which grabs keys
interactively  from whatever tty or ptty you are running the program on.
 You'll have to consult the docs on curses and how to use it in this
fashion.

The problem is you can't just ssh into your device and run the program
as it will fetch input from the terminal (and your remote keyboard)
which isn't what you want.  But if you can get it to run on the linux
console, it would work.  I have not idea how to do this in a
non-interactive startup fashion.

If your buttons are USB you might be able to read their status via
libusb but that gets complicated as Linux tries to grab it as a HID
keyboard.






More information about the Python-list mailing list