Search code examples
pythonevent-handlingwxpythonkeypressarrow-keys

respond to keypresses in python without generating a window


I'm doing some robotics programming in python, and I'd like to enable the keyboard to control the robot's movement. My only experience with something like this is writing a game in Java using SWT, and I imagine the basic idea here would be to make some keyboard event handlers and run a main execution loop.

From what I've read it seems like the recommended way to do this would be to use some kind of GUI library like pyglet or wxPython(no experience with any of them). However, I understand these require some kind of main window or canvas to operate, and I just want the keypress handling capabilities.

So, what's the most straightforward way to program keypress responses?


Solution

  • You could probably use pykeylogger http://sourceforge.net/apps/mediawiki/pykeylogger/index.php?title=Main_Page

    However using something like PyGame or wxpython is easiest, so are you absolutely sure you can't use those? For example, why can't you have a window initialized? Is your robot controlled by some sort of embedded microchip that can't handle windows? In that case, how is a keyboard connected?

    You should probably describe exactly how your robot is constructed.