How to use the asciimatics.event.KeyboardEvent function in asciimatics

To help you get started, we’ve selected a few asciimatics 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 pawamoy / aria2p / tests / test_interface.py View on Github external
up = KeyboardEvent(Screen.KEY_UP)
    down = KeyboardEvent(Screen.KEY_DOWN)
    left = KeyboardEvent(Screen.KEY_LEFT)
    right = KeyboardEvent(Screen.KEY_RIGHT)
    delete = KeyboardEvent(Screen.KEY_DELETE)
    esc = KeyboardEvent(Screen.KEY_ESCAPE)
    f1 = KeyboardEvent(Screen.KEY_F1)
    f2 = KeyboardEvent(Screen.KEY_F2)
    f3 = KeyboardEvent(Screen.KEY_F3)
    f4 = KeyboardEvent(Screen.KEY_F4)
    f5 = KeyboardEvent(Screen.KEY_F5)
    f6 = KeyboardEvent(Screen.KEY_F6)
    f7 = KeyboardEvent(Screen.KEY_F7)
    f8 = KeyboardEvent(Screen.KEY_F8)
    f9 = KeyboardEvent(Screen.KEY_F9)
    f10 = KeyboardEvent(Screen.KEY_F10)
    f11 = KeyboardEvent(Screen.KEY_F11)
    f12 = KeyboardEvent(Screen.KEY_F12)
    enter = KeyboardEvent(ord("\n"))
    space = KeyboardEvent(ord(" "))

    @staticmethod
    def hit(letter):
        return KeyboardEvent(ord(letter))

    @staticmethod
    def exc(value):
        return SpecialEvent(SpecialEvent.RAISE, value)

    @staticmethod
    def pass_frames(value):
        return SpecialEvent(SpecialEvent.PASS_N_FRAMES, value)
github pawamoy / aria2p / tests / test_interface.py View on Github external
left = KeyboardEvent(Screen.KEY_LEFT)
    right = KeyboardEvent(Screen.KEY_RIGHT)
    delete = KeyboardEvent(Screen.KEY_DELETE)
    esc = KeyboardEvent(Screen.KEY_ESCAPE)
    f1 = KeyboardEvent(Screen.KEY_F1)
    f2 = KeyboardEvent(Screen.KEY_F2)
    f3 = KeyboardEvent(Screen.KEY_F3)
    f4 = KeyboardEvent(Screen.KEY_F4)
    f5 = KeyboardEvent(Screen.KEY_F5)
    f6 = KeyboardEvent(Screen.KEY_F6)
    f7 = KeyboardEvent(Screen.KEY_F7)
    f8 = KeyboardEvent(Screen.KEY_F8)
    f9 = KeyboardEvent(Screen.KEY_F9)
    f10 = KeyboardEvent(Screen.KEY_F10)
    f11 = KeyboardEvent(Screen.KEY_F11)
    f12 = KeyboardEvent(Screen.KEY_F12)
    enter = KeyboardEvent(ord("\n"))
    space = KeyboardEvent(ord(" "))

    @staticmethod
    def hit(letter):
        return KeyboardEvent(ord(letter))

    @staticmethod
    def exc(value):
        return SpecialEvent(SpecialEvent.RAISE, value)

    @staticmethod
    def pass_frames(value):
        return SpecialEvent(SpecialEvent.PASS_N_FRAMES, value)

    @staticmethod
github pawamoy / aria2p / tests / test_interface.py View on Github external
self.type = event_type
        self.value = value


class Event:
    resize = SpecialEvent(SpecialEvent.RESIZE)
    pass_frame = SpecialEvent(SpecialEvent.PASS_N_FRAMES, 1)
    pass_tick = SpecialEvent(SpecialEvent.PASS_N_TICKS, 1)
    pass_half_tick = SpecialEvent(SpecialEvent.PASS_N_FRAMES, tui.Interface.frames / 2)
    pass_tick_and_a_half = SpecialEvent(SpecialEvent.PASS_N_FRAMES, tui.Interface.frames * 3 / 2)
    up = KeyboardEvent(Screen.KEY_UP)
    down = KeyboardEvent(Screen.KEY_DOWN)
    left = KeyboardEvent(Screen.KEY_LEFT)
    right = KeyboardEvent(Screen.KEY_RIGHT)
    delete = KeyboardEvent(Screen.KEY_DELETE)
    esc = KeyboardEvent(Screen.KEY_ESCAPE)
    f1 = KeyboardEvent(Screen.KEY_F1)
    f2 = KeyboardEvent(Screen.KEY_F2)
    f3 = KeyboardEvent(Screen.KEY_F3)
    f4 = KeyboardEvent(Screen.KEY_F4)
    f5 = KeyboardEvent(Screen.KEY_F5)
    f6 = KeyboardEvent(Screen.KEY_F6)
    f7 = KeyboardEvent(Screen.KEY_F7)
    f8 = KeyboardEvent(Screen.KEY_F8)
    f9 = KeyboardEvent(Screen.KEY_F9)
    f10 = KeyboardEvent(Screen.KEY_F10)
    f11 = KeyboardEvent(Screen.KEY_F11)
    f12 = KeyboardEvent(Screen.KEY_F12)
    enter = KeyboardEvent(ord("\n"))
    space = KeyboardEvent(ord(" "))

    @staticmethod
github pawamoy / aria2p / tests / test_interface.py View on Github external
def __init__(self, event_type, value=None):
        self.type = event_type
        self.value = value


class Event:
    resize = SpecialEvent(SpecialEvent.RESIZE)
    pass_frame = SpecialEvent(SpecialEvent.PASS_N_FRAMES, 1)
    pass_tick = SpecialEvent(SpecialEvent.PASS_N_TICKS, 1)
    pass_half_tick = SpecialEvent(SpecialEvent.PASS_N_FRAMES, tui.Interface.frames / 2)
    pass_tick_and_a_half = SpecialEvent(SpecialEvent.PASS_N_FRAMES, tui.Interface.frames * 3 / 2)
    up = KeyboardEvent(Screen.KEY_UP)
    down = KeyboardEvent(Screen.KEY_DOWN)
    left = KeyboardEvent(Screen.KEY_LEFT)
    right = KeyboardEvent(Screen.KEY_RIGHT)
    delete = KeyboardEvent(Screen.KEY_DELETE)
    esc = KeyboardEvent(Screen.KEY_ESCAPE)
    f1 = KeyboardEvent(Screen.KEY_F1)
    f2 = KeyboardEvent(Screen.KEY_F2)
    f3 = KeyboardEvent(Screen.KEY_F3)
    f4 = KeyboardEvent(Screen.KEY_F4)
    f5 = KeyboardEvent(Screen.KEY_F5)
    f6 = KeyboardEvent(Screen.KEY_F6)
    f7 = KeyboardEvent(Screen.KEY_F7)
    f8 = KeyboardEvent(Screen.KEY_F8)
    f9 = KeyboardEvent(Screen.KEY_F9)
    f10 = KeyboardEvent(Screen.KEY_F10)
    f11 = KeyboardEvent(Screen.KEY_F11)
    f12 = KeyboardEvent(Screen.KEY_F12)
    enter = KeyboardEvent(ord("\n"))
    space = KeyboardEvent(ord(" "))
github pawamoy / aria2p / tests / test_interface.py View on Github external
def __init__(self, event_type, value=None):
        self.type = event_type
        self.value = value


class Event:
    resize = SpecialEvent(SpecialEvent.RESIZE)
    pass_frame = SpecialEvent(SpecialEvent.PASS_N_FRAMES, 1)
    pass_tick = SpecialEvent(SpecialEvent.PASS_N_TICKS, 1)
    pass_half_tick = SpecialEvent(SpecialEvent.PASS_N_FRAMES, tui.Interface.frames / 2)
    pass_tick_and_a_half = SpecialEvent(SpecialEvent.PASS_N_FRAMES, tui.Interface.frames * 3 / 2)
    up = KeyboardEvent(Screen.KEY_UP)
    down = KeyboardEvent(Screen.KEY_DOWN)
    left = KeyboardEvent(Screen.KEY_LEFT)
    right = KeyboardEvent(Screen.KEY_RIGHT)
    delete = KeyboardEvent(Screen.KEY_DELETE)
    esc = KeyboardEvent(Screen.KEY_ESCAPE)
    f1 = KeyboardEvent(Screen.KEY_F1)
    f2 = KeyboardEvent(Screen.KEY_F2)
    f3 = KeyboardEvent(Screen.KEY_F3)
    f4 = KeyboardEvent(Screen.KEY_F4)
    f5 = KeyboardEvent(Screen.KEY_F5)
    f6 = KeyboardEvent(Screen.KEY_F6)
    f7 = KeyboardEvent(Screen.KEY_F7)
    f8 = KeyboardEvent(Screen.KEY_F8)
    f9 = KeyboardEvent(Screen.KEY_F9)
    f10 = KeyboardEvent(Screen.KEY_F10)
    f11 = KeyboardEvent(Screen.KEY_F11)
    f12 = KeyboardEvent(Screen.KEY_F12)
    enter = KeyboardEvent(ord("\n"))
    space = KeyboardEvent(ord(" "))
github peterbrittain / asciimatics / asciimatics / screen.py View on Github external
# If the user decided not to be cross-platform, so be
                        # it, otherwise map some standard bindings for extended
                        # keys.
                        if (self._map_all and
                                event.VirtualKeyCode in self._EXTRA_KEY_MAP):
                            key_code = self._EXTRA_KEY_MAP[event.VirtualKeyCode]
                        else:
                            if (event.VirtualKeyCode == win32con.VK_TAB and
                                    event.ControlKeyState &
                                    win32con.SHIFT_PRESSED):
                                key_code = Screen.KEY_BACK_TAB

                        # Don't return anything if we didn't have a valid
                        # mapping.
                        if key_code:
                            return KeyboardEvent(key_code)
                    else:
                        # Tidy up any key that was previously pressed.  At
                        # start-up, we may be mid-key, so can't assume this must
                        # always match up.
                        if key_code in self._keys:
                            self._keys.remove(key_code)

                elif event.EventType == win32console.MOUSE_EVENT:
                    # Translate into a MouseEvent object.
                    logger.debug("Processing mouse: %d, %d",
                                 event.MousePosition.X, event.MousePosition.Y)
                    button = 0
                    if event.EventFlags == 0:
                        # Button pressed - translate it.
                        if (event.ButtonState &
                                win32con.FROM_LEFT_1ST_BUTTON_PRESSED != 0):
github peterbrittain / asciimatics / asciimatics / widgets.py View on Github external
def process_event(self, event):
        if isinstance(event, KeyboardEvent):
            if len(self._options) > 0 and event.key_code == Screen.KEY_UP:
                # Move up one line in text - use value to trigger on_select.
                self._line = max(0, self._line - 1)
                self.value = self._options[self._line][1]
            elif len(self._options) > 0 and event.key_code == Screen.KEY_DOWN:
                # Move down one line in text - use value to trigger on_select.
                self._line = min(len(self._options) - 1, self._line + 1)
                self.value = self._options[self._line][1]
            elif len(self._options) > 0 and event.key_code == Screen.KEY_PAGE_UP:
                # Move up one page.
                self._line = max(0, self._line - self._h + (1 if self._titles else 0))
                self.value = self._options[self._line][1]
            elif len(self._options) > 0 and event.key_code == Screen.KEY_PAGE_DOWN:
                # Move down one page.
                self._line = min(
                    len(self._options) - 1, self._line + self._h - (1 if self._titles else 0))
github chrismaille / cabrita / cabrita / dashboard.py View on Github external
def process_event(self, event):
        """Summary

        Args:
            event (TYPE): Description

        Returns:
            TYPE: Description

        Raises:
            StopApplication: Description
        """
        # Do the key handling for this Frame.
        if isinstance(event, KeyboardEvent):
            if event.key_code in [ord('q'), ord('Q'), Screen.ctrl("c")]:
                raise StopApplication("User quit")

            # Force a refresh for improved responsiveness
            self._last_frame = 0

        # Now pass on to lower levels for normal handling of the event.
        return super(StatusFrame, self).process_event(event)
github peterbrittain / asciimatics / samples / interactive.py View on Github external
def process_event(self, event):
        if isinstance(event, KeyboardEvent):
            key = event.key_code
            if key == Screen.KEY_UP:
                self._y -= 1
                self._y = max(self._y, 2)
            elif key == Screen.KEY_DOWN:
                self._y += 1
                self._y = min(self._y, self._screen.height-2)
            elif key == Screen.KEY_LEFT:
                self._x -= 1
                self._x = max(self._x, 3)
            elif key == Screen.KEY_RIGHT:
                self._x += 1
                self._x = min(self._x, self._screen.width-3)
            else:
                return event
        else:
github kayagoban / shadowlands / mockup.py View on Github external
def process_event(self, event):
       #debug(self._screen._screen); import pdb; pdb.set_trace()
        #D for dapp
        if type(event) != KeyboardEvent:
            return None

        if event.key_code == 100:
            self._scene.add_effect(
                Materialize(self._screen, StaticRenderer([dapp_menu]), 15, 7)
                )
        else:
            return None