Key repeat after input in pynput

Question:

I basically need something to take input from and print it or something else, but whatever I press it will repeat after I (close the program, read text input, etc)

here is an example:

what I tried:

I used the keyboard module instead of pynput module
I used getch: it worked but not with keys like space,esc,up,down,etc

code:

from pynput.keyboard import Listener

kk=''
is_released=False
def getkey():
    def on_release(k):
        global is_released
        global kk
        kk=str(k)
        is_released=True
        return False

    with Listener(on_release=on_release) as listener:
        listener.join()
    print('b', end='')
    return kk

while True:
    print(getkey())
Asked By: Klesty Selimay

||

Answers:

https://pynput.readthedocs.io/en/latest/keyboard.html#pynput.keyboard.Listener

Parameters:

suppress (bool) – Whether to suppress events. Setting this to True will prevent the input events from being passed to the rest of the system.

Answered By: rasjani
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.