How to use the readchar.readkey function in readchar

To help you get started, we’ve selected a few readchar examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github FakeCola / LastMinuteFlashcards / lmf / last_minute_flashcards.py View on Github external
def run(self):
        while True:
            self.draw_main_page()
            if self.test_mode:
                self.mainwin.close()
                logging.info("Test finished. Bye bye")
                break

            pressed_key = readchar.readkey()
            if pressed_key not in COMMANDS:
                logging.warn("key %s can not be recognized" %
                             repr(pressed_key))
                continue
            # else
            cmd = COMMANDS[pressed_key]

            if cmd == 'ABORT':
                self.mainwin.close()
                raise KeyboardInterrupt

            elif cmd == 'QUIT':
                self.mainwin.close()
                logging.info("Bye bye")
                break
github eerimoq / simba / make / console.py View on Github external
if args.reset_type == 0:
        dev_serial.rts = 0
        dev_serial.dtr = 1
        time.sleep(0.5)
        # Let go of the reset.
        dev_serial.dtr = 0

    # Start the serial reader thread.
    serial_reader_thread = threading.Thread(target=serial_reader_main,
                                            args=(dev_serial, ))
    serial_reader_thread.setDaemon(True)
    serial_reader_thread.start()

    # Read user input.
    while True:
        key = readchar.readkey()

        # Break on CTRL-C.
        if key == readchar.key.CTRL_C:
            break

        if key == readchar.key.ENTER:
            dev_serial.write('\r\n')
        else:
            dev_serial.write(key)

    print()
github mmeyer724 / sshmenu / sshmenu / sshmenu.py View on Github external
call(['clear'])
    puts(colored.cyan('Available commands (press any key to exit)'))

    puts(' enter       - Connect to your selection')
    puts(' crtl+c | q  - Quit sshmenu')
    puts(' k (up)      - Move your selection up')
    puts(' j (down)    - Move your selection down')
    puts(' h           - Show help menu')
    puts(' c           - Create new connection')
    puts(' d           - Delete connection')
    puts(' e           - Edit connection')
    puts(' + (plus)    - Move connection up')
    puts(' - (minus)   - Move connection down')

    # Hang until we get a keypress
    readchar.readkey()
github FakeCola / LastMinuteFlashcards / lmf / player / listplayer.py View on Github external
def play(self, test_mode=True, shuffle=False):
        self.test_mode = test_mode
        self.shuffle = shuffle
        self.start()

        while True:
            pressed_key = readchar.readkey()
            if pressed_key not in COMMANDS:
                logging.warn("key %s can not be recognized" %
                             repr(pressed_key))
                continue
            # else
            cmd = COMMANDS[pressed_key]

            if cmd == 'ABORT':
                self.abort()

            elif cmd == 'QUIT':
                logging.info("quit current play")
                break

            elif cmd == 'PREVIOUS':
                self.previous()
github STJRush / rpi / Helpful python examples / readchar_example.py View on Github external
#Only for Python 2.7
#Very Important!!!!!!!!!
import readchar

while True:
	key = readchar.readkey()

	if key == "w":
		print("up")
	elif key == "s":
                print("down")
	elif key == "a":
                print("left")
	elif key == "d":
                print("right")


	elif key == "z":
		print("exiting")
		break
github Kamik423 / cutie / cutie.py View on Github external
"""
    is_yes = default_is_yes
    is_selected = enter_empty_confirms
    current_message = ''
    yn_prompt = f' ({yes_text[0]}/{no_text[0]}) ' if char_prompt else ': '
    print()
    while True:
        yes = is_yes and is_selected
        no = not is_yes and is_selected
        print('\033[K'
              f'{selected_prefix if yes else deselected_prefix}{yes_text}')
        print('\033[K'
              f'{selected_prefix if no else deselected_prefix}{no_text}')
        print('\033[3A\r\033[K'
              f'{question}{yn_prompt}{current_message}', end='', flush=True)
        keypress = readchar.readkey()
        if keypress in DefaultKeys.down or keypress in DefaultKeys.up:
            is_yes = not is_yes
            is_selected = True
            current_message = yes_text if is_yes else no_text
        elif keypress in DefaultKeys.delete:
            if current_message:
                current_message = current_message[:-1]
        elif keypress in DefaultKeys.interrupt:
            raise KeyboardInterrupt
        elif keypress in DefaultKeys.confirm:
            if is_selected:
                break
        elif keypress in '\t':
            if is_selected:
                current_message = yes_text if is_yes else no_text
        else:
github nalsil / kimhun_rl_windows / 01_play_frozenlake_det.py View on Github external
'\x1b[B' : DOWN,
    '\x1b[C' : RIGHT,
    '\x1b[D' : LEFT
}

register(
    id='FrozenLake-v3',
    entry_point='gym.envs.toy_text:FrozenLakeEnv',
    kwargs={'map_name' : '4x4', 'is_slippery': False}
)

env = gym.make('FrozenLake-v3')
env.render()

while True:
    key = readchar.readkey()
    if key not in arrow_keys.keys():
        print("Game aborted!")
        break

    action = arrow_keys[key]
    state, reward, done, info = env.step(action)
    env.render()
    print("State: ", state, "Action: ", action, "Reward: ", reward, "Info: ", info)

    if done:
        print("Finished with reward", reward)
        break
github STJRush / rpi / 4rovIR_AUTO.py View on Github external
print("-To EXIT the program, type... 5")
        choice=raw_input("Type now.")


        key="t"

        if choice=="1":
            print("             ^             ")
            print("    (O)------W------(0)    ")
            print("    [----------------]     ")
            print("<-A [----------------] D ->")
            print("    [----------------]     ")
            print("    (0)------S------(0)    ")
            print("                           ")
            print("Hold WASD to move. C stops. Z goes back to main menu")
            key=readchar.readkey()  #choose "hold down key" steering mode

        elif choice=="2":
            print("             ^             ")
            print("    (O)------W------(0)    ")
            print("    [----------------]     ")
            print("<-A [----------------] D ->")
            print("    [----------------]     ")
            print("    (0)------S------(0)    ")
            print("                           ")
            print("Control with WASD. Hit enter to go. C stops. Z goes back to main menu")
            key=raw_input("Enter command or press z and it return to exit")  #choose hit "enter" steering mode

        elif choice=="3":
            auto()
            
        elif choice=="4":

readchar

Library to easily read single chars and key strokes

MIT
Latest version published 17 days ago

Package Health Score

88 / 100
Full package analysis

Similar packages