按钮#

根据连接的是 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) 方法注册一个在按下按钮时调用的函数。

范围

描述

打回来

按下按钮时调用的函数。

**返回:**无。

// Define the buttonPressed function with a void return
// type, showing it doesn't return a value.
void buttonPressed() {
  // The Brain will print that a controller button was
  // pressed on the Brain's screen.
  Brain.Screen.print("controller button pressed");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run buttonPressed when the 'A' controller button is pressed.
  Controller.ButtonA.pressed(buttonPressed);
}

发布()#

released(callback) 方法注册一个在释放按钮时调用的函数。

范围

描述

打回来

释放按钮时调用的函数。

**返回:**无。

// Define the buttonReleased function with a void return
// type, showing it doesn't return a value.
void buttonReleased() {
  // The Brain will print that a controller button was
  // released on the Brain's screen.
  Brain.Screen.print("controller button released");
}

int main() {
  // Initializing Robot Configuration. DO NOT REMOVE!
  vexcodeInit();

  // Run buttonReleased when the 'A' controller button is released.
  Controller.ButtonA.released(buttonReleased);
}

紧迫()#

pressing() 方法返回按钮当前是否被按下。

返回: 如果按钮当前被按下,则返回 true。如果按钮当前未被按下,则返回 false