钟旭尧 <python_zh...@qq.com> added the comment:

I have an idea to solve it. But I don't know how to get the clipboard data.

The code like this (Windows):

def win_getpass(prompt='Password: ', stream=None, echoChar='*'):
    """Prompt for password with echo off, using Windows getwch()."""
    if not isinstance(echoChar, str) or len(echoChar) < 1 or len(echoChar) > 1:
        raise ValueError("Argument 'echoChar' is incorrect. It should be a 
character.")
    if sys.stdin is not sys.__stdin__:
        return fallback_getpass(prompt, stream)
    for c in prompt:
        msvcrt.putwch(c)
    pw = ""
    while 1:
        c = msvcrt.getwch()
        if ord(c) == 22: # User pressed Ctrl-V
            k = <Clipboard Info>
            pw += k
            for _ in range(len(k)):
                msvcrt.putwch(echoChar)
        if c == '\r' or c == '\n' or c == '\r\n':
            break
        if c == '\003':
            raise KeyboardInterrupt
        if c == '\b':
            if pw != '':
                pw = pw[:-1]
                count = len(pw)
                for _ in range(count+1):
                    msvcrt.putwch('\b')
                for _ in range(count):
                    msvcrt.putwch(echoChar)
                msvcrt.putwch(' ')
                msvcrt.putwch('\b')
        else:
            pw = pw + c
            msvcrt.putwch(echoChar)
            
    msvcrt.putwch('\r')
    msvcrt.putwch('\n')
    return pw

----------
nosy: +W_M
versions:  -Python 3.10, Python 3.8, Python 3.9

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue37426>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to