Block keyboard input in python

2019-09-07 16:02发布

问题:

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.

回答1:

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?



回答2:

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



标签: python input