Jul-29-2018, 10:23 AM
Jul-29-2018, 11:56 AM
https://pypi.org/project/readchar/
https://pypi.org/project/getkey/
https://pypi.org/project/getch/
Click also provides this as functionality http://click.pocoo.org/5/utils/#getting-...m-terminal
I think recently a noticed yet another one
https://pypi.org/project/getkey/
https://pypi.org/project/getch/
Click also provides this as functionality http://click.pocoo.org/5/utils/#getting-...m-terminal
I think recently a noticed yet another one
Jul-29-2018, 12:17 PM
I just had a post about getting keypress here.
So if i rewrite it a little.
Click work cross platform and solve Unicode for all shell(even
My tutorial about it.
See that i use
So if i rewrite it a little.
import msvcrt print('Would you like to go on y/n') while True: ch = msvcrt.getch() if ch in b'\x00': ch = msvcrt.getch() if ch == b'y': print('<y> typed going out') break if ch == b'q': break else: print(f'Key Pressed: {ch}')Test:
Output:E:\div_code
λ python scan_user.py
Would you like to go on y/n
Key Pressed: b'n'
Key Pressed: b'g'
Key Pressed: b't'
Key Pressed: b'r'
Key Pressed: b'e'
<y> typed going out
This is Windows only,as @buran mention Click which is my favorite CLI tool for Python.Click work cross platform and solve Unicode for all shell(even
cmd
Windows). My tutorial about it.
See that i use
b'y'
to get it to work Python 3.import click click.echo('Continue? [yn] ', nl=False) c = click.getchar() click.echo() if c == b'y': click.echo('We will go on') elif c == b'n': click.echo('Abort!') else: click.echo('Invalid input :(')Test:
Output:E:\div_code
λ python yn.py
Continue? [yn] # No Enter pressed
We will go on