按钮#

Depending on if it is an EXP Controller or a V5 Controller connected, the button attribute has access to different objects:

EXP 控制器

V5 控制器

  • buttonA - The A button.
  • buttonB - The B button.
  • buttonDown - The Down button.
  • buttonUp - The Up button.
  • buttonL1 - The L1 button.
  • buttonL2 - The L2 button.
  • buttonL3 - The L3 button.
  • buttonR1 - The R1 button.
  • buttonR2 - The R2 button.
  • buttonR3 - The R3 button.

  • buttonA - The A button.
  • buttonB - The B button.
  • buttonX - The X button.
  • buttonY - The Y button.
  • buttonDown - The Down button.
  • buttonUp - The Up button.
  • buttonLeft - The Left button.
  • buttonRight - The Right button.
  • buttonL1 - The L1 button.
  • buttonL2 - The L2 button.
  • buttonR1 - The R1 button.
  • buttonR2 - The R2 button.

按下()#

The pressed(callback, arg) method registers a function to be called when a Controller’s button is pressed.

范围

描述

打回来

按下按钮时调用的函数

arg

**可选。**用于向回调函数传递参数的元组。

**返回:**事件类的一个实例。

# Define a function button_pressed().
def button_pressed():
    # The Brain will print that the button was pressed on the
    # Brain's screen.
    brain.screen.print("button pressed")

# Run button_pressed() when L1 button is pressed.
controller.buttonL1.pressed(button_pressed)

发布()#

The released(callback, arg) method registers a function to be called when a Controller’s button is released.

范围

描述

打回来

释放按钮时调用的函数

arg

**可选。**用于向回调函数传递参数的元组。

**返回:**事件类的一个实例。

# Define a function button_released().
def button_released():
    # The Brain will print that the button was released on
    # the Brain's screen.
    brain.screen.print("button released")

# Run button_released() when the L1 button is released.
controller.buttonL1.released(button_released)

紧迫()#

The pressing() method returns whether a Controller’s button is currently being pressed.

Returns: True if the button is currently being pressed. False if it is not currently being pressed.