按钮#

button 属性中的对象

| IQ(第一代)控制器 | | :—————- | :—————–| |

  • ButtonEUp - 上方 E 按钮。
  • ButtonEDown - 下方 E 按钮。
  • ButtonFUp - 上方 F 按钮。
  • ButtonFDown - 下方 F 按钮。
  • ButtonLUp - 上方 L 按钮。
  • ButtonLDown - 下方 L 按钮。
  • ButtonRUp - 上方 R 按钮。
  • ButtonRDown - 下方 R 按钮。
  • |

    按下()#

    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 Left Up button is pressed 
      // on the controller.
      Controller.ButtonLUp.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 Left Up button is released 
      // on the controller.
      Controller.ButtonLUp.released(buttonReleased);
    }
    
    

    紧迫()#

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

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