Python Forum

Full Version: keyboard module question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

I installed the keyboard module for a simple task. I want the user to be able to input a letter representing a color.
This is a stripped down version of the app, but it shows the problem I have. Instead of accepting the user input (1 letter)
once it seems to perform a second loop, instead of waiting for the next letter. (At least it should work like that).
Why does it perform 2 loops, and not 7 or 1 ? If you are considering to run this, you may need to pip install keyboard.
import keyboard
#valid input letters 'a','b','c'...etc

def user_input():
    clr = keyboard.read_key(suppress=True)
    return clr

while True:
    clr =  user_input()
    print('color is', clr)
thx,
Paul