Register an [event handler](/reference/event-handler) that will execute whenever an input button (A, B, or A and B together) is pressed during program execution. When [running code](/device/simulator) with this function in a web browser, click an on-screen input button - labelled A or B.
This example counts how many times the left or right input button is pressed. Each time a button is pressed, the global count variable is increased by 1 and displayed on the screen.
```blocks
let count = 0
basic.showNumber(count)
input.onButtonPressed(Button.A, () => {
count++;
basic.showNumber(count);
})
```
### Example: roll a dice
This example generates a random number when you press the B input button, and then displays a random die image: