Python Keyboard module executing keys to next line in CLI

Viewed 9

I am creating a simple number only user input for CLI and also created it. But while using keyboard module when the user tries to press enter, the program closes perfectly, but the text that user enters gets executed in command line.


import keyboard
specials = "1234567890"
userinput = ""
no_of_presses = 0

print("Number to be doubled : ",end="",flush=True)

def show(e):
    global no_of_presses, userinput
    if(e.name in specials):
        print(e.name,end="",flush=True)
        no_of_presses+=1
        userinput+=e.name

def output(e):
    global userinput
    print(f"\noutput : {int(userinput)*2}")

keyboard.on_press(show)
keyboard.on_press_key("enter",output)
keyboard.wait("enter")

Here is the image of sample error I am getting enter image description here

0 Answers
Related