2

What I want to do is simple.

I have a code to detect when a key is pressed to proceed to different actions.

I made a test version of the code

import keyboard

print('test press a number key')

while True:
    try:
        if keyboard.is_pressed('1'):
            print('1')
            break
        if keyboard.is_pressed('2'):
            print('2')
            break
    except:
        break

input()

And here is the result on the console.

test press a number key
2
2

It shows me the '2' of the print function, and it also show me the '2' that I input. Basically, is there a way to make it so it doesn't show what I input on the console but just the prints?

1 Answer 1

3

In python use getpass:

import getpass
secret_input = getpass.getpass(prompt="Enter hidden input: ")

on non windows or unix systems you can turn off echo for regular input with:

import os
os.system("stty -echo")

and turn it back on with:

os.system("stty echo")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.