How to use the pynput.keyboard function in pynput

To help you get started, we’ve selected a few pynput 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 moses-palmer / pynput / tests / keyboard_listener_tests.py View on Github external
def normalize(event):
            if not isinstance(event[0], tuple):
                return normalize(((event[0],), event[1]))
            key, is_pressed = event
            return (
                tuple(
                    pynput.keyboard.KeyCode.from_char(key)
                    if isinstance(key, six.string_types)
                    else key.value if key in pynput.keyboard.Key
                    else key
                    for key in event[0]),
                is_pressed)
github jackosx / CAMP / PythonSketches / mq_keyguitar.py View on Github external
def on_press(key):
    try:
        if key not in keys_pressed:
            keys_pressed.add(key)
            if key == keyboard.Key.space:
                print("strumming")
                client.publish(guitar_topic + 's', 100)
                return
            k = key.char
            # if k.isalpha() and k in valid_keys:
                # guitar.play_note(k)
            if k.isdigit() and int(k) < 5:
                client.publish(guitar_topic + 'f', k)
            if k == 's':
                client.publish(guitar_topic + 's', 100)

        # print('alphanumeric key {0} pressed'.format(key.char))
    except AttributeError:
        print('special key {0} pressed'.format(key))
    except ValueError:
        print('error playing note')
github grantjenks / free-python-games / docs / demo.py View on Github external
def worker():
    global slide
    while True:
        key = inputs.get()
        if key == kb.Key.esc:
            print('Typing slide', slide)
            parts = slides[slide]
            for part in parts:
                if part == '':
                    pyautogui.press('enter')
                    time.sleep(0.25)
                elif part == -1:
                    pyautogui.press('backspace')
                elif isinstance(part, str):
                    pyautogui.typewrite(part, interval=0.1)
                    pyautogui.press('enter')
                else:
                    time.sleep(part)
            slide += 1
github lanshiqin / JerryMouse / keyboard_mouse.py View on Github external
def on_release(key):
                if key == keyboard.Key.esc:
                    # 停止监听
                    startListenerBtn['text'] = '开始录制'
                    startListenerBtn['state'] = 'normal'
                    MouseActionListener.esc_key = True
                    keyboardListener.stop()
                    return False
                template = keyboard_action_template()
                template['event'] = 'release'
                try:
                    template['vk'] = key.vk
                except AttributeError:
                    template['vk'] = key.value.vk
                finally:
                    file.writelines(json.dumps(template) + "\n")
                    file.flush()
github xiebruce / PicUploader / accessorys / PicUploaderHelper / PicUploaderHelper.py View on Github external
""" Listen button press event  """
        if config['debug'] == 1:
            logging.info(str(key))
        if any([key in COMBO for COMBO in COMBINATIONS]):
            current.add(key)
            if any(all(k in current for k in COMBO) for COMBO in COMBINATIONS):
                upload_image()


    def on_release(key):
        """ Listen button release event """
        if any([key in COMBO for COMBO in COMBINATIONS]):
            current.remove(key)


    with keyboard.Listener(on_press=on_press, on_release=on_release) as listener:
        """ start a keyboard listener """
        listener.join()
github K40Nano / K40Nano / Keyburn.py View on Github external
def on_release(key):
    print('{0} released'.format(key))
    if key == keyboard.Key.esc:
        if not plotter.exit_compact_mode_finish():
            plotter.close()
            return False
        return True
    if key == keyboard.Key.space:
        plotter.up()
github javirk / Dino-AI / Main.py View on Github external
logger = logging.getLogger('main')

logger.info(f'Programa lanzado. Datos: Número de genes: {numGenes}, '
            f'Probabilidad de mutación: {mutationProb}, Genes seleccionados: {selection}')
logger.info(f'Se ha elegido el modo {mode}')
logger.info('Loading genome...')
genome = Genome(numGenes, mutationProb, selection, folder,  nGenerations)
logger.info('The genome was successfully loaded')

game = Game(mode, nGenerations, numGenes)

if mode == 'TRAINING':
    logger.info(f'Training will last {nGenerations} generations.')
    for i in range(1,  nGenerations):
        with keyboard.Listener(on_press=keys.on_press) as listener:
            if not keys.break_program: #End key to stop a running program by the end of the generation.
                genome.execute_generation(game)

                if (i % 5 == 0 and i != 0) or i == nGenerations:
                    genome.save_all()

                genome.kill_and_reproduce()
            else:
                genome.save_all()
                break

        listener.join()

else:
    with keyboard.Listener(on_press=keys.on_press) as listener:
        if not keys.break_program:
github shanefarris / RTFM / Framework / Screen.py View on Github external
def on_press(self, key):
        #keyboard.type('test')
        if key == keyboard.Key.up:
            keyboard.type('UP\n')
            self._cmdHistoryIndex -= 1
        elif key == keyboard.Key.down:
            keyboard.type('DOWN\n')
            self._cmdHistoryIndex += 1

        if self._cmdHistoryIndex < 0:
            self._cmdHistoryIndex == 0;
        elif self._cmdHistoryIndex > (len(self._cmdHistory) - 1):
            self._cmdHistoryIndex = len(self._cmdHistory) - 1

        return