How to use the pynput.keyboard.KeyCode.from_char 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_hotkey_tests.py View on Github external
def test_activate_combo(self):
        activations = []
        def on_activate():
            activations.append(True)

        hk = HotKey({k.ctrl, kc.from_char('a')}, on_activate)

        hk.press(kc.from_char('b'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(0, len(activations))

        hk.press(k.ctrl)
        self.assertEqual(0, len(activations))
        hk.release(k.ctrl)
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.press(kc.from_char('a'))
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
def test_activate_single(self):
        activations = []
        def on_activate():
            activations.append(True)

        hk = HotKey({kc.from_char('a')}, on_activate)

        hk.press(kc.from_char('b'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(1, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(1, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
hk.press(k.ctrl)
        self.assertEqual(0, len(activations))
        hk.release(k.ctrl)
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.release(k.ctrl)
        hk.press(k.ctrl)
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
        hk.press(kc.from_char('a'))
        self.assertEqual(3, len(activations))
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(1, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(1, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(2, len(activations))

        hk.press(kc.from_char('A'))
        self.assertEqual(3, len(activations))
        hk.release(kc.from_char('A'))
        self.assertEqual(3, len(activations))
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
def test_activate_combo(self):
        activations = []
        def on_activate():
            activations.append(True)

        hk = HotKey({k.ctrl, kc.from_char('a')}, on_activate)

        hk.press(kc.from_char('b'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(0, len(activations))

        hk.press(k.ctrl)
        self.assertEqual(0, len(activations))
        hk.release(k.ctrl)
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(0, len(activations))

        hk.press(k.ctrl)
        self.assertEqual(0, len(activations))
        hk.release(k.ctrl)
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.press(kc.from_char('a'))
        hk.press(k.ctrl)
        self.assertEqual(1, len(activations))
        hk.release(k.ctrl)
        hk.press(k.ctrl)
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
        hk.press(kc.from_char('a'))
        self.assertEqual(3, len(activations))
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
def test_activate_single(self):
        activations = []
        def on_activate():
            activations.append(True)

        hk = HotKey({kc.from_char('a')}, on_activate)

        hk.press(kc.from_char('b'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(1, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(1, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(2, len(activations))
github moses-palmer / pynput / tests / keyboard_hotkey_tests.py View on Github external
def test_activate_single(self):
        activations = []
        def on_activate():
            activations.append(True)

        hk = HotKey({kc.from_char('a')}, on_activate)

        hk.press(kc.from_char('b'))
        self.assertEqual(0, len(activations))
        hk.release(kc.from_char('b'))
        self.assertEqual(0, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(1, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(1, len(activations))

        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.press(kc.from_char('a'))
        self.assertEqual(2, len(activations))
        hk.release(kc.from_char('a'))
        self.assertEqual(2, len(activations))

        hk.press(kc.from_char('A'))
        self.assertEqual(3, len(activations))
        hk.release(kc.from_char('A'))
        self.assertEqual(3, len(activations))
github moses-palmer / pynput / lib / pynput / keyboard / _base.py View on Github external
def _normalize(self, key):
        """Performs normalisation of a key.

        :param key: The key to normalise.
        :type key: Key or KeyCode

        :return: a key
        :rtype: Key or KeyCode
        """
        from pynput.keyboard import Key, KeyCode, _NORMAL_MODIFIERS
        if isinstance(key, KeyCode) and key.char is not None:
            return KeyCode.from_char(key.char.lower())
        elif isinstance(key, Key) and key.value in _NORMAL_MODIFIERS:
            return _NORMAL_MODIFIERS[key.value]
        else:
            return key
github taojy123 / KeymouseGo / pynput_demo.py View on Github external
keyboard_listener = keyboard.Listener(
    on_press=on_press,
    on_release=on_release)
keyboard_listener.start()


time.sleep(1)


# ============ keyboard control ============ 
keyboard_ctl = keyboard.Controller()

keyboard_ctl.press('a')
keyboard_ctl.release('a')

keyboard_ctl.press(KeyCode.from_char('b'))
keyboard_ctl.release(KeyCode.from_char('b'))

keyboard_ctl.press(Key.space)
keyboard_ctl.release(Key.space)

keyboard_ctl.press(getattr(Key, 'shift'))
keyboard_ctl.press('c')
keyboard_ctl.release('c')
keyboard_ctl.release(getattr(Key, 'shift'))

keyboard_ctl.press(KeyCode.from_vk(11))
keyboard_ctl.release(KeyCode.from_vk(11))

time.sleep(5)