按钮#
V5 控制器上可用的按钮如下:
V5 控制器 |
---|
|
按下()#
The pressed(callback)
method registers a function to be called when a button is pressed.
范围 |
描述 |
---|---|
打回来 |
按下按钮时调用的函数。 |
**返回:**事件类的一个实例。
// 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);
}
发布()#
The released(callback, arg)
method registers a function to be called when a button is released.
范围 |
描述 |
---|---|
打回来 |
释放按钮时调用的函数。 |
arg |
**可选。**传递给回调函数的参数。 |
**返回:**事件类的一个实例。
// 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);
}
紧迫()#
The pressing()
method returns whether a button is currently being pressed.
返回: 如果按钮当前被按下,则返回 True。如果按钮当前未被按下,则返回 False。