Python 3 - 如何在不按的情况下输入数据在操作系统中
我试图在游戏中使用“asdw”键移动角色,但我找不到一种在不按回车键的情况下不断输入数据的方法。我看到在Windows上有一个名为msvcrt的模块,它有一个getch函数,所以我想知道是否有一种方法可以在OSX中模拟它,或者更简单地不断地从键盘输入数据。
I am attempting to move a character using the "asdw" keys in a game, but I cannot find a way to constantly input data without pressing return. I have seen that on windows there is a module called msvcrt, which has a getch function, so I am wondering if there is a way to simulate this in OSX, or more simply to just constantly input data from the keyboard.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试使用curses库:
Curses 是一个用于控制终端的库,还包括绘制框形状等功能。它可在任何 POSIX 兼容系统上使用,包括 Mac OS X 和 GNU/Linux。
这是一个例子:
Try the
curses
library:Curses is a library for controlling the terminal, and includes features such as drawing box shapes as well. It's available on any POSIX-compatible system, which includes Mac OS X and GNU/Linux.
Here's an example:
您可以使用 Turtle 执行以下操作:
按下某个键时调用什么函数
You can use Turtle to do something like this:
What function to call when a certain key is pressed