boppreh / keyboard

Hook and simulate global keyboard events on Windows and Linux.
MIT License
3.8k stars 435 forks source link

Input autocompleted after handled 'enter' key #510

Open lngb opened 2 years ago

lngb commented 2 years ago

Hello to everyone, i'm using keyboard package and it's really powerful.. thank you for it.

I'm just facing with a problem with the following code:

    import keyboard

    def presentation():
            input("Name: ")
            input("Surname: ")

    def my_keyboard_hook(keyboard_event):
        if keyboard_event.name == "enter":
            print("You have pressed the key: " + keyboard_event.name)
            presentation()
        elif keyboard_event.name == "space":
            print("You have pressed the key: " + keyboard_event.name)

    keyboard.on_press(my_keyboard_hook)
    keyboard.wait()

Could anyone explain to me, why if I choose to catch the 'enter' key when i call the presentation() function, the first input is auto-completed ?

If I choose another key, the problem isn't available anymore, but i need the 'enter' key for submit the input. Thank you in advance !!!

aliig commented 2 years ago

facing a similar issue, did you ever find a solution?

lngb commented 2 years ago

facing a similar issue, did you ever find a solution?

Hi ! I solved using the Curses library.

https://docs.python.org/3/howto/curses.html

It's customisable solution and highly interactive, on YouTube you can find some useful guide.

Bye !