I am working on a python project and I have got the following questions. How to catch a character in python ? What modules I need to use ? What functions I need to use?
Asked
Active
Viewed 820 times
0
-
1Read up on http://stackoverflow.com/questions/5404068/how-to-read-keyboard-input – Girrafish Aug 05 '16 at 15:58
-
Use punput https://pypi.python.org/pypi/pynput – Gaurav Dhama Aug 05 '16 at 16:00
1 Answers
1
If you need to take a line of input just use:
x = input('Your name: ')
y = input()
Or (For Python 2)
x = raw_input('Your name: ')
y = raw_input()
For taking just one character from the keyboard you can use msvcrt.getch()
:
import msvcrt
key = msvcrt.getch()
if key == 'a':
print("You pressed a")

Ciprum
- 734
- 1
- 11
- 18