I am trying to make a program that prints out a sentence with pynput by only pressing one key, however if that sentence contains that particular key it just starts typing that sentence infinite times. I would like to find a way to ignore the inputs from pynput, but not from my keyboard. Thanks in advance.
code:
from pynput.keyboard import Key, Listener, Controller
kb = Controller()
def on_press(key):
if not 'char' in dir(key):
return
if key.char == "s":
kb.press(Key.backspace) # deletes "s"
kb.release(Key.backspace)
kb.type("sample")
return
def on_release(key):
if key == Key.esc:
return False
with Listener(on_press=on_press, on_release=on_release) as listener:
listener.join()
output: samplsamplsamplsampl....