2016-03-25 16:47:20 -07:00
# Button Is Pressed
2016-11-01 17:44:37 -07:00
Check whether a button is pressed right now. The @boardname @ has two buttons: button `A` and button `B` .
2016-03-25 16:47:20 -07:00
```sig
input.buttonIsPressed(Button.A);
```
2017-09-07 13:42:08 -07:00
## Parameters
2016-03-25 16:47:20 -07:00
2017-03-16 07:57:41 -07: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-25 16:47:20 -07:00
2017-09-07 13:42:08 -07:00
## Returns
2016-03-25 16:47:20 -07:00
2019-02-08 13:48:49 -08:00
* a [boolean ](/blocks/logic/boolean ) value that is `true` if the button you are checking is pressed, `false` if it is not pressed.
2016-03-25 16:47:20 -07:00
2017-09-07 13:42:08 -07:00
## Example
2016-03-25 16:47:20 -07:00
2019-02-08 13:48:49 -08:00
This program uses an [``||logic:if||`` ](/blocks/logic/if ) to run
2016-05-20 16:05:45 -07:00
one part of the program if the `A` button is pressed, and
another part if it is not pressed.
2016-03-25 16:47:20 -07:00
```blocks
basic.forever(() => {
let pressed = input.buttonIsPressed(Button.A)
if (pressed) {
2016-05-20 16:05:45 -07:00
// this part runs if the A button is pressed
2019-02-08 13:48:49 -08:00
basic.showNumber(1)
2016-03-25 16:47:20 -07:00
} else {
2016-05-20 16:05:45 -07:00
// this part runs if the A button is *not* pressed
2019-02-08 13:48:49 -08:00
basic.showNumber(0)
2016-03-25 16:47:20 -07:00
}
})
```
2019-02-08 13:48:49 -08:00
Find out how buttons provide input to the @boardname @ in this video:
https://www.youtube.com/watch?v=t_Qujjd_38o
2017-09-07 13:42:08 -07:00
## See also
2016-03-25 16:47:20 -07:00
2016-06-14 17:20:45 -04:00
[on button pressed ](/reference/input/on-button-pressed ), [if ](/blocks/logic/if ), [forever ](/reference/basic/forever )
2016-03-25 16:47:20 -07:00