How do I get realtime keyboard input in Python?

雨燕双飞 提交于 2019-12-01 21:40:43

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

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

If you are using Windows you can use the msvcrt module. Specifically, look at kbhit to check whether a key is waiting to be read and getch to read a key press. The user does not need to press enter for the key presses to be made available to your program.

You could look into PyHook. It provides callbacks for reading mouse and keyboard events.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!