Odd Button Pressed behavior?

Simple code: in an On Button A Pressed box I include Show Icon X, Pause two seconds then Show Icon O, and wait for another press. If I press A and release it right away (within about 1 second) all works as expected. But if I wait more than about a second before releasing A it ignores the action. Bug? Documented?
TIA Don

@Don23805 please share a link to your code!

2 Likes

Not sure if this will work, but here goes

It DOES work !
Actually very simple

1 Like

The micro:bit actually fires a “long pressed” event when you hold down the button for more than 1 second. The “on button pressed” block only waits for the short click event. We don’t actually surface any blocks to use the long pressed event, but if you happen to know the event id value (which is 4) you can subscribe to it using the generic event block from the control category:

1 Like

@Don23805 The Button Clicks extension provides a few more options with buttons, like the ability to detect when a button is just pressed down (not a press/release combo that the default “on pressed” detects). It also provides detection of single clicks vs. double clicks and press/holds.

Here’s a variation of your example using the extension’s on button down: https://makecode.microbit.org/S25570-81546-11007-69922 . It will miss additional “button down” events if it’s not yet done handling previous ones, so it won’t respond to additional clicks down in the ~2.1s interval it’s dealing with prior clicks.

If you want to catch all button presses, it’s possible to count clicks. and use a forever loop to handle them: https://makecode.microbit.org/S04105-41320-76538-12318 .