def which_pressed(player, *buttons: Button, refresh_input=False):
    """Checks which of the given buttons are pressed.

    Parameters
    ----------
    player: :class:`Player`
        The player to check with.
    buttons: one or more :class:`Button` objects OR Tuple[Button]
        Buttons to check for.
    refresh_input: Optional[bool]
        Whether or not to check for new inputs.
        Checks with inputs from last refresh if False.
        Defaults to False.

    Returns
    -------
    A list of :class:`Button` objects.
    """
    if refresh_input:
        _nx.hid_scan_input()
    keys_pressed = _nx.hid_keys_down(player.number - 1 if player.number != 1 else AUTO_PLAYER_1_ID)
    if not buttons:
        raise TypeError("At least one Button must be passed")
    if refresh_input:
        refresh_inputs()
    keys_pressed = _nx.hid_keys_down(player.number - 1 if player.number != 1 else AUTO_PLAYER_1_ID)
    buttons_pressed = []
    for button in buttons:
        for key_bit in button.key_bits:
            if keys_pressed & key_bit:
                buttons_pressed.append(button)
    return buttons_pressed
def any_pressed(player, *buttons: Button, refresh_input=False):
    """Checks if any of the given buttons are pressed, or if
    any buttons are pressed at all in case no buttons are given.

    Parameters
    ----------
    player: :class:`Player`
        The player to check with.
    buttons: Optional[one or more :class:`Button` objects OR Tuple[Button]]
        Buttons to check for. Checks if no Button is pressed if none given.
    refresh_input: Optional[bool]
        Whether or not to check for new inputs.
        Checks with inputs from last refresh if False.
        Defaults to False.
    """
    if refresh_input:
        refresh_inputs()
    keys_pressed = _nx.hid_keys_down(player.number - 1 if player.number != 1 else AUTO_PLAYER_1_ID)
    if len(buttons) == 0:
        return not keys_pressed == 0
    for button in buttons:
        for key_bit in button.key_bits:
            if keys_pressed & key_bit:
                return True
    return False
    def y(self):
        """
        The current y value of the analogue stick

        :return: The float value of the stick's y location.
        :rtype: float
        """
        keys_pressed = _nx.hid_keys_down(self.player.number - 1 if self.player.number != 1 else AUTO_PLAYER_1_ID)
        if keys_pressed & self.up_key_bit:
            return 1.0
        if keys_pressed & self.down_key_bit:
            return -1.0
        return 0.0
Пример #4
0
def poll_input(self):
    if self.firstrun:
        # todo: do this differently to prevent delay when placing marker near the bottom of the screen
        self.console.write(b" " +
                           bytes("\n" * self.selected_idx + "\r>\r", 'UTF-8'))
        self.firstrun = False
    _nx.hid_scan_input()
    keys_down = _nx.hid_keys_down(self.CONTROLLER_P1_AUTO)

    if keys_down & self.KEY_A:
        return True
    elif keys_down & (1 << 10):
        raise ExitToHBMenu
    elif keys_down & self.KEY_UP:
        if self.selected_idx > 0:
            self.selected_idx -= 1
            self.console.write(b" \x1b[1A\r>\r")
            self.console.flush()
    elif keys_down & self.KEY_DOWN:
        if self.selected_idx < len(self.entries) - 1:
            self.selected_idx += 1
            self.console.write(b" \n\r>\r")
            self.console.flush()
    elif keys_down & (1 << 14):
        if self.selected_idx < len(self.entries) - 5:
            self.selected_idx += 5
            self.console.write(b" \n\n\n\n\n\r>\r")
            self.console.flush()
        else:
            self.console.write(
                bytes(
                    (" " + "\n" *
                     ((len(self.entries) - 1) - self.selected_idx)) + "\r>\r",
                    "UTF-8"))
            self.selected_idx = len(self.entries) - 1
            self.console.flush()
    elif keys_down & (1 << 12):
        if self.selected_idx > 5:
            self.selected_idx -= 5
            self.console.write(b" \x1b[1A\x1b[1A\x1b[1A\x1b[1A\x1b[1A\r>\r")
            self.console.flush()
        else:
            self.console.write(
                bytes((" " + "\x1b[1A" * self.selected_idx) + "\r>\r",
                      "UTF-8"))
            self.selected_idx = 0
            self.console.flush()

    return False
    def poll_input(self):
        _nx.hid_scan_input()
        keys_down = _nx.hid_keys_down(self.CONTROLLER_P1_AUTO)

        if keys_down & self.KEY_A:
            return True
        elif keys_down & self.KEY_UP:
            if self.selected_idx > 0:
                self.selected_idx -= 1
                self.console.write(b" \x1b[1A\r>\r")
                self.console.flush()
        elif keys_down & self.KEY_DOWN:
            if self.selected_idx < len(self.entries) - 1:
                self.selected_idx += 1
                self.console.write(b" \n\r>\r")
                self.console.flush()

        return False