[Python] Python keyboard module doesn’t recognize alphanumeric key presses

Discussão em 'Python' iniciado por Stack, Julho 11, 2025.

  1. Stack

    Stack Membro Participativo

    I’m working on a program to recognize what keys a person has pressed. My code currently looks something like this:

    import keyboard

    while True:
    if keyboard.is_pressed('a'):
    print('you pressed a!')
    elif keyboard.is_pressed('esc'):
    print('you pressed esc!')


    The program properly recognizes presses of keys such as esc, space, etc. However, it raises the value error

    Key ‘a’ is not mapped to any known key.

    If I switch to checking keyboard.is_pressed(ord('a')) I no longer get the value error but it instead never recognizes that a (or other alphanumeric characters) has been pressed.

    How do I fix this so I can read these characters from the keyboard?

    Continue reading...

Compartilhe esta Página