按钮#
根据连接的是 EXP 控制器还是 V5 控制器,“按钮”属性可以访问不同的对象:
EXP 控制器 |
V5 控制器 |
---|---|
<ul><li>`buttonA` - A 按钮。</li><li>`buttonB` - B 按钮。</li><li>`buttonDown` - 向下按钮。</li><li>`buttonUp` - 向上按钮。</li><li>`buttonL1` - L1 按钮。</li><li>`buttonL2` - L2 按钮。</li><li>`buttonL3` - L3 按钮。</li><li>`buttonR1` - R1 按钮。</li><li>`buttonR2` - R2 按钮。</li><li>`buttonR3` - R3 按钮。 |
<ul><li>`buttonA` - A 按钮。</li><li>`buttonB` - B 按钮。</li><li>`buttonX` - X 按钮。</li><li>`buttonY` - Y 按钮。</li><li>`buttonDown` - 向下按钮。</li><li>`buttonUp` - 向上按钮。</li><li>`buttonLeft` - 左按钮。</li><li>`buttonRight` - 右按钮。</li><li>`buttonL1` - L1 按钮。</li><li>`buttonL2` - L2 按钮。</li><li>`buttonR1` - R1 按钮。</li><li>`buttonR2` - R2 按钮。</li> |
按下()#
pressed(callback, arg)
方法注册一个当控制器的按钮被按下时要调用的函数。
范围 |
描述 |
---|---|
打回来 |
按下按钮时调用的函数 |
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)
发布()#
released(callback, arg)
方法注册一个在控制器的按钮被释放时调用的函数。
范围 |
描述 |
---|---|
打回来 |
释放按钮时调用的函数 |
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)
紧迫()#
pressing()
方法返回控制器的按钮当前是否被按下。
返回: 如果按钮当前被按下,则返回 True
。如果按钮当前未被按下,则返回 False
。