Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/python
- # just a dirty unbuffered getch()
- import sys, tty, termios
- def raw_getch():
- setbak = termios.tcgetattr(sys.stdin.fileno())
- try:
- tty.setraw(sys.stdin.fileno())
- ch = sys.stdin.read(1)
- finally:
- termios.tcsetattr(sys.stdin.fileno(), termios.TCSADRAIN, setbak)
- return ch
- # binary keyboard, use u and d keys to select the line
- def bin_select(chars):
- while len(chars) > 1:
- upper = chars[0:len(chars)/2]
- lower = chars[len(chars)/2:len(chars)]
- print ''.join(upper)
- print ''.join(lower)
- inp = raw_getch()
- if inp == 'u':
- chars = upper
- elif inp == 'd':
- chars = lower
- return chars[0]
- if __name__ == '__main__':
- chars = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N',
- 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1',
- '2', '3', '4', '5', '6', '7', '8', '9', '.', ',', '-', '_']
- print bin_select(chars)
Advertisement
Add Comment
Please, Sign In to add comment