e3975e65e5
* Accessibility changes
1.1 KiB
1.1 KiB
Button Is Pressed
Check whether a button is pressed right now. The @boardname@ has two buttons: button A
and button B
.
input.buttonIsPressed(Button.A);
Parameters
button
is a String. You should storeA
in it to check the left button,B
to check the right button, orA+B
to check both at the same time.
Returns
- Boolean that is
true
if the button you are checking is pressed,false
if it is not pressed.
Example
This program uses an if to run
one part of the program if the A
button is pressed, and
another part if it is not pressed.
basic.forever(() => {
let pressed = input.buttonIsPressed(Button.A)
if (pressed) {
// this part runs if the A button is pressed
basic.showNumber(1, 150)
} else {
// this part runs if the A button is *not* pressed
basic.showNumber(0, 150)
}
})