简体   繁体   中英

Is there any way to return input() in python if user enters backspace?

Is there any way to return the user's input after pressing backspace in python rather than just enter key? I know how to get user's input by using text = input("> ") and using keyboard.is_pressed('\\b') to check if user enters backspace using keyboard module. But I wanted to check that while user is typing. Is there a way to do it?

msvcrt library works for me

PS : I use windows OS

import msvcrt
x="hehe"
data=""
while x!="\b":
    x=msvcrt.getch()
    x=x.decode("utf-8")
    data+=x
print("Gotcha !",data)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM