jeudi 30 septembre 2021

Why does the code in line 21 not get executed? [duplicate]

When lastInputs equals ['.', 'c', 'w'] the code inside should be executed but it doesn't work.

Here is the code:

from pynput import keyboard

loops = 0
lastInput = '0'
lastInputs = ['', '', '']

def on_release(key):
    lastInput = key
    
    loops = 0
    while loops < len(lastInputs):
        lastInputs[loops - len(lastInputs)] = lastInputs[loops + 1 - len(lastInputs)]
        loops += 1
    lastInputs[-1] = lastInput

    if key == keyboard.Key.esc:
        # Stop listener
        return False

    if lastInputs == ['.', 'c', 'w']:
        print('Printed')
    print(lastInputs)

# Collect events until released
with keyboard.Listener(
        on_release=on_release) as listener:
    listener.join()

Aucun commentaire:

Enregistrer un commentaire