import os import getch from time import sleep def fileWrite(text): with open('the-record-getch3.txt', 'a') as file: file.write(text) file.close() while 1: text = getch.getch() # sleep(1) print(text) fileWrite(text)