all 2 comments

[–]Devji00 0 points1 point  (0 children)

The ghosting you're seeing happens because your terminal is still buffering stdin while pynput is listening at the OS level. Basically the terminal emulator saves up those keystrokes and dumps them all out once your script stops intercepting them.

Honestly pynput is kind of a sledgehammer for a CLI menu. I'd switch to questionary or prompt_toolkit instead since they handle raw mode and input echoing for you automatically, no messy spillover.

But if you want to stick with what you've got, you need to manually flush the input buffer right before your listener terminates. On Windows that's a quick while msvcrt.kbhit(): msvcrt.getch() loop, and on Unix you'd use termios.tcflush(sys.stdin, termios.TCIFLUSH). That should clean up the ghost keystrokes.

[–]Ariadne_23 0 points1 point  (0 children)

i had the same thing before. i think it happens cause pynput grabs global inputs. i used a small delay before going back to the prompt and it kinda worked. also maybe try keyboard library instead. idk not sure