from __future__ import absolute_import, division, unicode_literals, print_function

import tty, termios
import sys
if sys.version_info.major < 3:
    import thread as _thread
else:
    import _thread
import time


try:
    from msvcrt import getch  
except ImportError:
    def getch():   
        fd = sys.stdin.fileno()
        old_settings = termios.tcgetattr(fd)
        try:
            tty.setraw(sys.stdin.fileno())
            ch = sys.stdin.read(1)
        finally:
            termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
        return ch

def keypress():
    global char
    char = getch()

def main():
    global char
    char = None
    _thread.start_new_thread(keypress, ())

    while True:
        if char is not None:
            try:
                print( + char.decode('utf-8'))
            except UnicodeDecodeError:
                print()
                char = None
            _thread.start_new_thread(keypress, ())
            if char == 'q' or char == '\x1b':  
                exit()
            char = None
        print()
        time.sleep(1)

if __name__ == :
    main()