'Read live data from terminal python

I am working on a program where I am trying to check to see if there are any characters that have been typed in the terminal in real time (before ENTER or any other key is pressed). I saw that

result = subprocess.run(cmd, stdout=subprocess.PIPE, input=<input>)

could potentially be used to read commands, but I was unsure how to put that in a loop so I could constantly check without requiring any input once the program is running. Would I potentially be able to use pygame or another library similar to help?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source