Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

183
Vistas
Suppress user input keypress while executing autogenerated keypress Python

My problem here is I want to have any keystroke the user types execute a automatic keystroke. However, I would like only the user generated keystroke to be suppressed. I am trying to do this with pynput like this:

def on_press(key):
    if key == keyboard.Key.esc:
        return False

def on_release(key):
    if key == keyboard.Key.esc:
        return False
    elif len(words) > i:
        c.press(words[i])
        i += 1
    else:
        c.press(keyboard.Key.space)
        return False

with keyboard.Listener(on_press=on_press, on_release=on_release, suppress=True) as listener:
    listener.join()

I think that the problem is that the keypress call inside of the on_press() function also calls to the listener function and this creates infinite recursion. If I keep the suppressor on nothing is typed but the program keeps infinitely recursing. If I turn the suppressor off both the user keypress is executed and the autogenerated key press is executed recursively.

But if I keypress outside of the on_press() function like below it only executes if I exit the listener.

with keyboard.Listener(on_press=on_press, on_release=on_release, suppress=True) as listener:
    listener.join()
    if key == keyboard.Key.esc:
        return False
    elif len(words) > i:
        c.press(words[i])
        i += 1
    else:
        c.press(keyboard.Key.space)
        return False

Does anyone have a workaround to this?

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda