0

Much like how google tries to auto-guess what is being input by the user. I am trying to figure out how much and what the user has typed before hitting enter. More difficult, I am trying to get this done through the console.

Although the input function does exist and is very easy to use.

var = input("Enter Name: ")
print(f'Hello, {var}')

I am trying to get this input 'dynamically'

Is this even possible? I imagine the code would look like:

var = imaginary_input("Enter Name: ")
while not var.complete:
    current_input = var.get()

Is there a function that works similar to my 'imaginary_input' function? Any help is greatly appreciated.

(I understand that this can easily be completed through a window with a textbox, but I would prefer this to be done over the console)

Pranav Hosangadi
  • 23,755
  • 7
  • 44
  • 70
Rushil S
  • 78
  • 6
  • 1
    Have you looked at the `keyboard` module? https://pypi.org/project/keyboard/ – Samwise Dec 03 '20 at 19:10
  • I have, but that wouldn't work since the user could always click off the terminal, type something and my code would be confused. – Rushil S Dec 03 '20 at 19:17
  • If Python's `readline` module is available on your platform, you might be able to do something with its word completion feature. – jasonharper Dec 03 '20 at 19:23
  • @RushilS Does [this](https://stackoverflow.com/questions/510357/how-to-read-a-single-character-from-the-user) answer your question? – ssp Dec 03 '20 at 19:34

1 Answers1

1

This should answer your question.

So for example if you're using windows:

import msvcrt

while (c := msvcrt.getch()) != b'\r':
    # Do something with read byte character
    print(c)
ssp
  • 1,666
  • 11
  • 15