import curses import os import random def main(bildschirm): bildschirm.clear() maxY, maxX = bildschirm.getmaxyx() bildschirm.addstr(1, 0, f"({maxY}, {maxX})") curses.mousemask(curses.BUTTON1_CLICKED) for y in range(maxY): for x in range(maxX): try: bildschirm.addstr(y, x, " ") except curses.error as e: pass xPos = maxX // 2 yPos = maxY // 2 while True: bildschirm.addstr(0, 0, f"({yPos}, {xPos})") zeichen = chr(bildschirm.inch(yPos, xPos) & 0xFF) if zeichen == " ": neu = "A" elif zeichen == "Z": neu = "A" else: neu = chr(ord(zeichen) + 1) try: bildschirm.addstr(yPos, xPos, neu) except curses.error as e: pass bildschirm.move(yPos, xPos) taste = bildschirm.getch() bildschirm.addstr(1, 0, str(taste)) if taste == curses.KEY_UP: if yPos > 0: yPos = yPos - 1 elif taste == curses.KEY_DOWN: if yPos + 1 < maxY: yPos = yPos + 1 elif taste == curses.KEY_LEFT: xPos = max(xPos - 1, 0) elif taste == curses.KEY_RIGHT: xPos = min(xPos + 1, maxX - 1) elif taste == curses.KEY_MOUSE: mausID, mausX, mausY, mausZ, drueckZustand = curses.getmouse() if 0 <= mausX < maxX and 0 <= mausY < maxY: xPos = mausX yPos = mausY elif taste == 27: break # https://stackoverflow.com/questions/27372068/why-does-the-escape-key-have-a-delay-in-python-curses os.environ.setdefault('ESCDELAY', '25') curses.wrapper(main)