![thonny raspberry pi pygame thonny raspberry pi pygame](https://kofler.info/wp-content/uploads/thonny-micropython.png)
We use termios.tcgetattr(sys.stdin) to retrieve the current settings of the terminal on the stdin stream. Both tty and termios modules are required to make sure the terminal reads the input per character. Termios.tcsetattr(sys.stdin, termios.TCSADRAIN, filedescriptors) Code Explanationįirstly, import the sys module along with tty and termios modules. Code for Keyboard Input import tty, sys, termiosįiledescriptors = termios.tcgetattr(sys.stdin) A Linux-based system instantly creates these three streams when you execute a command/program. Stdin accepts text input while Stdout and Stderr get data from the output. The whole channel consists of the standard input, standard output, and standard error streams. If you’re not familiar with the standard input stream, think of it as a part of a communication channel between a program and its development environment. It is used by the Python interpreter to gain access to the standard input stream.
![thonny raspberry pi pygame thonny raspberry pi pygame](https://domblox.de/wp-content/uploads/2020/04/raspipins-768x459.png)
The main function that we’re going to use from this module is stdin.
#Thonny raspberry pi pygame install
It comes as a default to the Python package, so no need to install explicitly.
![thonny raspberry pi pygame thonny raspberry pi pygame](https://www.pi-shop.ch/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/_/1/_16495_gamepi15-13.jpg)
The sys module provides functions that control particular aspects of the Python runtime environment. Let’s talk more about them in the next section. I tried a few of these methods, and for me, using the standard sys and pygame modules are the easiest to use. For instance, the keyboard module requires root user privileges. Unfortunately, they all have characteristics that make them hard to implement on a Raspberry Pi. There’s the keyboard module, ncurses, etc. A simple Google search reveals Python modules that support keyboard and mouse input detection on a Linux system.