[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2022-02-25 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
nosy:  -terry.reedy
versions: +Python 3.11

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2022-02-25 Thread Eryk Sun


Eryk Sun  added the comment:

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

In Windows, using the window manager entails extending the process and the 
current thread with GUI-related structures in the kernel and then connecting 
the process to a window station (usually "WinSta0", which contains the 
clipboard) and connecting the thread to a desktop (usually "Default"). This 
permanently changes how the OS sees the process. I think whether or not the 
process should be a GUI process is something for the application to decide, not 
the standard library. Thus getpass should not read text from the clipboard.

The docs could note that terminals may need to be configured to support 
Ctrl+Shift+C (copy) and Ctrl+Shift+V (paste) shortcuts, and that some terminals 
provide alternate ways to paste text, such as a right-click action or context 
menu. I don't think the docs should provide detailed explanations and 
configuration details for particular terminals.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2022-02-25 Thread Eryk Sun


Eryk Sun  added the comment:

> Clicking `Edit > Paste` from the window menu
> Use right-click to paste

In particular, if the console has quick-edit mode enabled, then you can paste 
text by right-clicking. Also, if text is selected in quick-edit mode, 
right-clicking copies to the clipboard.

> Enabling `Properties > Options > Use Ctrl+Shift+C/V as Copy/Paste` from the 
> menu

I prefer this setting because it matches the behavior of terminals on other 
platforms. I suggest setting it in the "Defaults" dialog instead of 
"Properties". Otherwise, you'll have to configure it individually for each 
shell link (.LNK file) or session title. (The console session title defaults to 
the executable path, unless set in STARTUPINFO.)

> Using the new Windows Terminal

Terminal allows configuring the actions for keyboard shortcuts. By default it 
grabs Ctrl+C (copy) and Ctrl+V (paste). I disable these mappings. I leave the 
default mappings in place for Ctrl+Shift+C (copy), Ctrl+Shift+V (paste), 
Ctrl+Insert (copy), and Shift+Insert (paste).  

> This behavior is the same Command Prompt and PowerShell

The behavior has to be the same when the parent process is a normal console 
shell such as CMD or PowerShell. Python inherits its console session from the 
shell, and that's the extent of the shell's involvement. 

A console session is hosted by an instance of conhost.exe or openconsole.exe. 
If the host is running in pseudoconsole (headless) mode, then the user 
interface for the session is hosted by another application (e.g. Windows 
Terminal). Even in pseudoconsole mode, however, the console host a lot to do in 
order to manage the session state for the console API.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2022-02-25 Thread 钟旭尧

钟旭尧  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 = 
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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2020-08-23 Thread Terry J. Reedy


Change by Terry J. Reedy :


--
versions:  -Python 3.6, Python 3.7

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2020-08-23 Thread Brian Rutledge


Brian Rutledge  added the comment:

In addition to Ctrl+V, Shift+Insert also doesn't work. This behavior is the 
same Command Prompt and PowerShell on Windows 10.

Workarounds include:

- Clicking `Edit > Paste` from the window menu
- Enabling `Properties > Options > Use Ctrl+Shift+C/V as Copy/Paste` from the 
menu
- Use right-click to paste
- Using the new Windows Terminal: 
https://www.microsoft.com/en-us/p/windows-terminal/9n0dx20hk701

I stumbled upon this issue while investigating 
https://github.com/pypa/twine/issues/671. Thanks for writing it up!

--
nosy: +bhrutledge2
versions: +Python 3.10, Python 3.7, Python 3.8, Python 3.9

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2019-07-02 Thread Atul Bagga


Atul Bagga  added the comment:

Suprisingly this works fine on ConEMU which I commonly use on windows though 
internally I still use powershell on conemu. 
https://conemu.github.io/

It does not work on CMD and Powershell consoles.

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2019-06-28 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

If anything, this seems to be a getpass doc issue.

--
assignee:  -> docs@python
components: +Documentation -Library (Lib), Windows
nosy: +docs@python, terry.reedy

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2019-06-27 Thread Eryk Sun


Eryk Sun  added the comment:

getpass() reads from the console via msvcrt.getwch(). This is a raw console 
read, so Ctrl+V is read as the SYN (0x16) control character. Only the following 
keys are handled specially by getpass: 

* Ctrl+C - raise KeyboardInterrupt
* Ctrl+H (backspace) - delete the previous character
* Ctrl+J (linefeed) and Ctrl+M (return) - return

getpass() behaves pretty much the same in a Linux terminal emulator, except 
Ctrl+H isn't backspace. 

Recent versions of the console host in Windows 10 have an option to support 
pasting via Ctrl+Shift+V, regardless of the input mode. This is pretty common 
in Unix terminal emulators as well. You can change this setting in the 
Properties->Options dialog for a particular window or shortcut, or the default 
setting in the Defaults->Options dialog. In the "HKCU\Console" registry key, 
the DWORD value name is "InterceptCopyPaste".

--
nosy: +eryksun

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2019-06-27 Thread Karthikeyan Singaravelan


Change by Karthikeyan Singaravelan :


--
components: +Windows
nosy: +paul.moore, steve.dower, tim.golden, zach.ware

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue37426] getpass.getpass not working with on windows when ctrl+v is used to enter the string

2019-06-27 Thread Atul Bagga


New submission from Atul Bagga :

Detailed issue filed here - https://github.com/microsoft/knack/issues/160

--
components: Library (Lib)
messages: 346721
nosy: Atul Bagga
priority: normal
severity: normal
status: open
title: getpass.getpass not working with on windows when ctrl+v  is used to 
enter the string
type: behavior
versions: Python 3.6

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com