Hi all, I'm both a Pi and Python novice and was wondering about the most efficient way to read the state of the keyboard in Python on the Pi.
I'd like to do something like read the state of a key every 1/10th of a second, and do something, otherwise continue executing as normal.
Code: Select all
while True:
key = read_state(SPECIFIC KEY) #Return True is key is pressed
if key:
do something
time.sleep(0.1)
The important thing is that I don't want my script to stop and wait for user input to continue execution. I know that pygame has some of these functions, but I'd like to access them without initializing pygame's graphical overhead - I'd like this script to be entirely command-line based.
Any help would be appreciated, and sorry if this isn't clear! Thanks!