def key_down(self, event):
        """Handles key presses to select and activate menu items or dismiss it.
        :param event: object: The event to be processed."""
        key = self.root.getKey(event)
        last_index = len(self._items) - 1
        # Just define a dummy method when scrolling is not necessary.
        def _x(*args, **kwargs):
            """..."""
            pass

        def page_up_down(*args, **kwargs):
            """Triggers scroll alignment to see the selected item on page up/down event."""
            self.scroll = min(self._selected_item_index, last_index - self.scroll_items + 1)

        view_meth = _x
        if key == "Up":
            if self._selected_item_index == 0:
                self._selected_item_index = last_index
                self.scroll = last_index - self.scroll_items + 1
            else:
                self._selected_item_index -= 1
                view_meth = self.scroll_up
        elif key == "Down":
            if self._selected_item_index == last_index:
                self._selected_item_index = 0
                self.scroll = 0
            else:
                self._selected_item_index += 1
                view_meth = self.scroll_down
        elif key == "Page up":
            self._selected_item_index = max(0, self._selected_item_index - self.scroll_items)
            view_meth = page_up_down
        elif key == "Page down":
            self._selected_item_index = min(last_index, self._selected_item_index + self.scroll_items)
            view_meth = page_up_down
        elif key in ("Return", "Enter", "Space"):
            self.dismiss(self._selected_item_index)
        elif key == "Escape":
            self.dismiss(False)
        else:
            Dialog.key_down(self, event)

        self._hilited = self._items[self._selected_item_index]

        # Ensure the selected item is visible by scrollign accordingly
        if self._hilited not in self._items[self.scroll:self.scroll + self.scroll_items]:
            view_meth()
Handles key presses to select and activate menu items or dismiss it.
        :param event: object: The event to be processed.
albow/menu.py