コード例 #1
0
ファイル: state.py プロジェクト: nickgashkov/jocus
    def update(self, window: curses.window) -> None:
        self.player.move(window.getkey())
        self.player.maybe_grab_coin(self.coins)

        if not self.coins and not self.is_finished:
            self.is_finished = True
            voice.say("оа")
            voice.say("молодец")
コード例 #2
0
def threadGetKeys(win: curses.window, net: Network) -> None:
    while 1:
        try:
            key = win.getkey()
            win.addstr(" KEY = " + key)

            GlobVar.currentMovement = "Stop"
            if GlobVar.connectedToPi:
                if key == "KEY_UP":
                    GlobVar.currentMovement = "Go Forward"
                    GlobVar.last_answer = net.robotGoForward()
                elif key == "KEY_DOWN":
                    GlobVar.currentMovement = "Go Backward"
                    GlobVar.last_answer = net.robotGoBackward()
                elif key == "KEY_RIGHT":
                    GlobVar.currentMovement = "Go Right"
                    GlobVar.last_answer = net.robotGoRight()
                elif key == "KEY_LEFT":
                    GlobVar.currentMovement = "Go Left"
                    GlobVar.last_answer = net.robotGoLeft()
                elif key == " ":
                    GlobVar.currentMovement = "Stop"
                    GlobVar.last_answer = net.robotStop()
                elif key == "R" or key == 'r':
                    GlobVar.last_answer = net.robotReset()
                    GlobVar.dumberStarted = False
                elif key == "U" or key == 'u':
                    GlobVar.last_answer = net.robotStartWithoutWatchdog()
                    if GlobVar.last_answer == net.ACK:
                        GlobVar.dumberStarted = True
                    else:
                        GlobVar.dumberStarted = False
                elif key == "W" or key == 'w':
                    GlobVar.last_answer = net.robotStartWithWatchdog()
                    if GlobVar.last_answer == net.ACK:
                        GlobVar.dumberStarted = True
                    else:
                        GlobVar.dumberStarted = False
                elif key == "C" or key == 'c':
                    GlobVar.last_answer = net.robotCloseCom()
                    GlobVar.connectedToDumber = False
                    GlobVar.dumberStarted = False
                elif key == "O" or key == 'o':
                    GlobVar.last_answer = net.robotOpenCom()
                    if GlobVar.last_answer == net.ACK:
                        GlobVar.connectedToDumber = True
                    else:
                        GlobVar.connectedToDumber = False

            #if key == os.linesep or key =='q' or key == 'Q':
            #    break

        except Exception as e:
            GlobVar.exceptionmsg = "Exception received: " + str(e)
コード例 #3
0
ファイル: client2.py プロジェクト: Nighmared/discord-bot
def curses_get_input(stdscr: curses.window, inputwin: curses.window,
                     msgqueue: Queue, status):
    to_send = ""
    next_char_x = 2
    next_char_y = 0
    inputwin.addstr(0, 0, ">>")
    inputwin.refresh()
    while status.run:
        curr_in = inputwin.getkey()
        with open("keys.log", "a") as f:
            f.write(f"got {curr_in}")
        if curr_in == "\n":
            msgqueue.put(to_send)
            to_send = ""
            inputwin.erase()
            next_char_x = next_char_y = 0
            inputwin.addstr(next_char_y, next_char_x, ">>")
            next_char_x += 2
        elif curr_in == 'KEY_BACKSPACE' or curr_in == curses.KEY_BACKSPACE or curr_in == "^?" or curr_in == "\b" or curr_in == '\x7f':
            with open("clientdebug.log", "a") as f:
                f.write(f"got key {curr_in} went into backspace case\n")
            if next_char_x == 2 and next_char_y == 0:
                continue  #nothing to delete
            if next_char_x == 0 and next_char_y > 0:  # at the start of a new line
                next_char_y -= 1
                next_char_x = INPUT_WIDTH - 1
            elif (next_char_x > 0 and next_char_y > 0) or next_char_x > 2:
                next_char_x -= 1

            inputwin.addstr(next_char_y, next_char_x, " ")
            inputwin.move(next_char_y, next_char_x)
            to_send = to_send[:-1]
        else:
            to_send += curr_in
            inputwin.addstr(next_char_y, next_char_x, curr_in)
            next_char_x += 1
            if next_char_x == INPUT_WIDTH:
                next_char_x = 0
                next_char_y += 1

        inputwin.refresh()