-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.py
More file actions
30 lines (25 loc) · 697 Bytes
/
input.py
File metadata and controls
30 lines (25 loc) · 697 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
''' This block is used to input characters from terminal '''
from __future__ import print_function
from getch import _getChUnix as getChar
import signal
class AlarmException(Exception):
'''This class executes the alarmexception.'''
pass
def getpress():
''' moves Mandalorian'''
def alarmhandler(signum, frame):
''' input method '''
raise AlarmException
def user_input(timeout=0.15):
''' input method '''
signal.signal(signal.SIGALRM, alarmhandler)
signal.setitimer(signal.ITIMER_REAL, timeout)
try:
text = getChar()()
signal.alarm(0)
return text
except AlarmException:
pass
signal.signal(signal.SIGALRM, signal.SIG_IGN)
return ''
return user_input()