from ctypes import * import msvcrt STD_OUTPUT_HANDLE = -11 class COORD(Structure): _fields_ = [("X", c_short), ("Y", c_short)] class CONSOLE_CURSOR_INFO(Structure): _fields_ = [("dwSize", c_uint32), ("bVisible", c_int)] ### print_at(c,r,s) ### prints the string s at the position (c|r) ### c is the column ### r is the row ### s is the string def print_at(c, r, s): h = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) windll.kernel32.SetConsoleCursorPosition(h, COORD(c, r)) c = s.encode("windows-1252") windll.kernel32.WriteConsoleA(h, c_char_p(c), len(c), None, None) ### showCursor(b) ### sets the cursor visible if b is True ### and invisible if b is False def showCursor(b): h = windll.kernel32.GetStdHandle(STD_OUTPUT_HANDLE) c= CONSOLE_CURSOR_INFO() c.dwSize = 1 if b: c.bVisible = 1 else: c.bVisible = 0 windll.kernel32.SetConsoleCursorInfo(h, byref(c)) ### readkey() ### returns the last key pressed as string ### will wait for a key to be pressed if the buffer is empty ### the key will not be displayed on the console def readkey(): s = msvcrt.getch() return s.decode() ### kbhit() ### returns True if a pressed key is in the keyboard buffer ### False otherwise def kbhit(): return msvcrt.kbhit()