2016-03-26 00:47:20 +01:00
# Button Is Pressed
2016-11-02 01:44:37 +01:00
Check whether a button is pressed right now. The @boardname @ has two buttons: button `A` and button `B` .
2016-03-26 00:47:20 +01:00
```sig
input.buttonIsPressed(Button.A);
```
### Parameters
2017-03-16 15:57:41 +01:00
* ``button`` is a [String ](/types/string ). You should store `A` in it to check the left button, `B` to check the right button, or `A+B` to check both at the same time.
2016-03-26 00:47:20 +01:00
### Returns
2016-06-15 13:55:19 +02:00
* [Boolean ](/blocks/logic/boolean ) that is `true` if the button you are checking is pressed, `false` if it is not pressed.
2016-03-26 00:47:20 +01:00
### Example
2016-06-14 23:20:45 +02:00
This program uses an [if ](/blocks/logic/if ) to run
2016-05-21 01:05:45 +02:00
one part of the program if the `A` button is pressed, and
another part if it is not pressed.
2016-03-26 00:47:20 +01:00
```blocks
basic.forever(() => {
let pressed = input.buttonIsPressed(Button.A)
if (pressed) {
2016-05-21 01:05:45 +02:00
// this part runs if the A button is pressed
2016-03-26 00:47:20 +01:00
basic.showNumber(1, 150)
} else {
2016-05-21 01:05:45 +02:00
// this part runs if the A button is *not* pressed
2016-03-26 00:47:20 +01:00
basic.showNumber(0, 150)
}
})
```
### See also
2016-06-14 23:20:45 +02:00
[on button pressed ](/reference/input/on-button-pressed ), [if ](/blocks/logic/if ), [forever ](/reference/basic/forever )
2016-03-26 00:47:20 +01:00