Block keyboard input in python

2019-09-07 16:16发布

In Python, is there a way to prevent the user from entering anything via keyboard, so that terminal output does not get cluttered by unneeded input?

In my case, the user is supposed to press and hold a key to register a specific keyboard - so, the actual input (as in input()) is not needed, but only clutters the output and menu.

标签: python input
2条回答
ゆ 、 Hurt°
2楼-- · 2019-09-07 16:29

I would recommend pygame. http://www.pygame.org/download.shtml It allows you to read all keyboard keys as you like. Here's an example of how the code would look: How to get keyboard input in pygame?

查看更多
男人必须洒脱
3楼-- · 2019-09-07 16:48

It sounds like you want the terminal contents to redraw themselves on user input?

https://docs.python.org/3/howto/curses.html or https://docs.python.org/2.7/howto/curses.html depending on python version.

See also this question Dynamic terminal printing with python

查看更多
登录 后发表回答