Keypress Input
Gary Herron
gherron at digipen.edu
Wed Jun 3 14:47:06 EDT 2015
On 06/03/2015 11:22 AM, John McKenzie wrote:
> Hello.
>
> Very new to Python and looking for some basic help.
>
> Would like a set-up where something happens when a key is pressed. Not
> propose a question, have the user type something, then hit return, then
> something happens, but just the R key is pressed, something happens, then
> something else happens if the B key is pressed, then a third thing
> happens if the G key is pressed.
>
> My research only served to confuse me. Firstly, I do not understand how
> it is possible for this to be a difficult thing not built into the system
> for any scripting language made within the last few decades. More to the
> point I am unclear on specific suggestions. Most of them seem to be for
> Windows only and I want this working on a Raspberry Pi. Saw getch but I
> am still confused if it is platform specific or not, or requires a module
> to be installed or not. Just get errors if I try to install getch using
> PIP.
If you are using Python through a CLI (command line interface i.e., a
shell), then in fact your request doesn't really make sense. CLIs by
their nature don't support that kind of interaction.
BUT don't despair. Nearly every GIU framework on the planet has a
Python interface, and they all allow for a window to be opened with
event processing of your choice.
This are some good places to start:
https://wiki.python.org/moin/GuiProgramming
https://wiki.python.org/moin/GUI%20Programming%20in%20Python
Several of these (Tkinter and the curses module) are distributed with
Python, so you should already have them installed.
Gary Herron
>
> Other suggestions seemed to be overkill and confused me to due to my
> beginner level knowledge and the fact these suggestions have other, more
> complicated elements to them.
>
> I just want a button press on a device connected to a Raspberry Pi to
> trigger an action. If anyone can give me some guidance on this I would
> appreciate it.
>
> Thank you.
>
--
Dr. Gary Herron
Department of Computer Science
DigiPen Institute of Technology
(425) 895-4418
More information about the Python-list
mailing list