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

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

问题描述

这可能吗?我看过的每个答案都不是我想要的.我所做的就像在 omega-rpg(这是一个很棒的基于文本的小型 debian rpg)中一样,但是使用 Python 而不是 C.与我正在做的事情有关.使用 raw_input()/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()/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.

推荐答案

我认为在 while 循环中使用 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天全站免登陆