0

How can I do to validate what the user enters by keyboard with Python?

13th Nov 2019, 4:56 PM
Juan Miguel Campos Marchan
Juan Miguel Campos Marchan - avatar
7 Respostas
+ 6
Are you talking about regular input with the input() function, or are you talking about detecting a key press (single key without input() function)?
13th Nov 2019, 5:28 PM
Lothar
Lothar - avatar
+ 3
Maybe this way: answer = input("y or n") if answer == "y" : some code if answer == "n" : some other code
13th Nov 2019, 5:31 PM
Coding Cat
Coding Cat - avatar
+ 2
Ah, ok. I think Lothar will help. And here is a Modul. Maybe this is what are you looking for https://pypi.org/project/keyboard/
13th Nov 2019, 7:58 PM
Coding Cat
Coding Cat - avatar
+ 2
Here you can find some helpful information. Be aware, that there can be problems with a platform independent solution. https://stackoverflow.com/questions/24072790/detect-key-press-in-JUMP_LINK__&&__python__&&__JUMP_LINK
13th Nov 2019, 8:34 PM
Lothar
Lothar - avatar
0
I am talking about detecting a keypress
13th Nov 2019, 7:46 PM
Juan Miguel Campos Marchan
Juan Miguel Campos Marchan - avatar
0
You can import "os" module and use it to find users, then give them permission with "if/else" For example my user is "Mehran" so I try this code: ``` import os if os.getlogin() == "Mehran": a = input() else: print("Permission denied!") ```
14th Nov 2019, 5:59 AM
Mehran sanea
Mehran sanea - avatar
0
you must install keyboard module if you'r on windows python -m pip install keyboard there is some methods in this module to find which keys pressed by user. search this article in stackoverflow website to see what i'm sayin: detect key press in python
14th Nov 2019, 5:59 PM
Mohammad Gk
Mohammad Gk - avatar