[Python] How to skip checking for keys if no key is pressed

Discussão em 'Python' iniciado por Stack, Janeiro 23, 2025.

  1. Stack

    Stack Membro Participativo

    I am making a text-based game with frames, and my problem right now is that I have the code to check for keypresses

    key = getkey.getkey()


    But it seems like that command waits for you to press a key to continue with the code (that is, the command is blocking), and I would just like the game to continue updating, even if you don't press a key.

    I was thinking of something like this:

    import getkey

    ##Rest of my code

    if key_pressed(any):
    key = getkey.getkey()


    I'm using the getkey library, and I'm on the Replit webapp if that helps. I can't use something like msvcrt because I am on Linux.

    Continue reading...

Compartilhe esta Página