在Python中响应按键而不生成窗口
我正在用 python 进行一些机器人编程,我想启用键盘来控制机器人的运动。我对此类事情的唯一经验是使用 SWT 在 Java 中编写游戏,我想这里的基本想法是创建一些键盘事件处理程序并运行主执行循环。
从我读到的内容来看,推荐的方法似乎是使用某种 GUI 库,如 pyglet 或 wxPython(没有使用它们的经验)。但是,我知道这些需要某种主窗口或画布才能操作,而我只想要按键处理功能。
那么,对按键响应进行编程最直接的方法是什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可能可以使用 pykeylogger http://sourceforge.net/apps/mediawiki/ pykeylogger/index.php?title=Main_Page
然而,使用 PyGame 或 wxpython 之类的东西是最简单的,所以你绝对确定你不能使用它们吗?例如,为什么不能初始化一个窗口?您的机器人是否由某种无法处理窗户的嵌入式微芯片控制?那么,键盘是如何连接的呢?
您可能应该准确描述您的机器人是如何构造的。
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.
你看过《火焰兵》吗? http://pyrorobotics.org/
如果您使用的是 Lego Mindstorms 之类的东西,可以使用 http://code.google.com/p/nxt-python/
Have you looked at Pyro? http://pyrorobotics.org/
If you're using something like Lego Mindstorms, there's http://code.google.com/p/nxt-python/