如何获取实时键盘输入在Python? [英] How do I get realtime keyboard input in Python?

查看:2651
本文介绍了如何获取实时键盘输入在Python?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这可能吗?我已经看过每一个答案,是不是我想要的。我做的虽然是在像ω-RPG (这是一个真棒小文本的基于Debian的篮板),但在Python,而不是C.我已经捅了一圈,发现一些东西,但没有什么是有关我在做什么。难道只是更容易使用的raw_input() / 输入,或会是更有效地使用某种形式的API这样做的?

Is this possible? Every answer I have looked at isn't what I want. What I do though is something like in omega-rpg (which is an awesome little text-based debian rpg), but in Python instead of C. I have poked around and found some things, but nothing that's relevant to what I'm doing. Is it just easier to use raw_input() / input, or would it be more efficient to use some kind of API for doing so?

清理:

我需要在Python实时键盘输入的系统,但我不知道它是否更易于使用的API或只是的raw_input()/输入()。如果这是更好地使用API​​,这是一个初学者级别的程序员使用?最好的之一

I need a system of realtime keyboard input in Python, but I don't know whether it's easier to use an API or just raw_input() / input(). If it IS better to use an API, which is the best one for a beginner-level programmer to use?

还有:

任何解决方案将在基于文本的游戏中使用!回答时,请记住这一点,谢谢。

Any solution will be used in a TEXT-BASED GAME! Keep that in mind when answering, please.

推荐答案

我觉得在循环使用的raw_input()是一个可接受的解决方案。

I think using raw_input() in a while loop is an acceptable solution.

你也可以考虑像 pygame的这将处理主游戏循环给你,同时也提供输入处理。

You could also look into something like pygame which would handle the main game loop for you and also offers input handling.

这篇关于如何获取实时键盘输入在Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆