[Python] Input() that constantly updates

Discussão em 'Python' iniciado por Stack, Maio 30, 2025.

  1. Stack

    Stack Membro Participativo

    I'd say the easiest way to describe this would be movement. Instead of requiring the user to press Enter after answering the input script,

    player_x = 0
    player_y = 0
    while true:
    user_input = str(input(""))
    #The user types something and has to press ENTER before the script continues running
    if user_input == 'w':
    player_y = player_y + 1
    elif user_input == 'a':
    player_x = player_x - 1
    elif user_input == 's':
    player_y = player_y - 1
    elif user_input == 'd':
    player_x = player_x + 1


    I also need the script to continue running even with the "input()" actively checking. Instead of requiring the user to press ENTER before the script continues, is there a way for it to actively check if the prompt is NOT EMPTY and run the following script(s) without the user having to press ENTER?

    player_x = 0
    player_y = 0
    while true:
    {input() script I dont have that I need}
    #The input the user makes is automatically detected without the script pausing while waiting
    if user_input == 'w':
    player_y = player_y + 1
    elif user_input == 'a':
    player_x = player_x - 1
    elif user_input == 's':
    player_y = player_y - 1
    elif user_input == 'd':
    player_x = player_x + 1


    For the following rambling: Key: NU-No Update ; U-Updates by a pixel I need this script because, can you imagine how annoying it would be to play a game and having to go -W- (NU) -Enter- (U) -W- (NU) -Enter- (U) ... and you move a few pixels, instead of just holding down -W- have it automatically smoothly update?

    Continue reading...

Compartilhe esta Página