# Button delay and repeat rate

**URL:** https://forum.makecode.com/t/button-delay-and-repeat-rate/470
**Category:** Arcade
**Created:** [August 23, 2019, 3:43pm UTC](https://forum.makecode.com/t/button-delay-and-repeat-rate/470 "2019-08-23T15:43:33Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kjw](https://avatars.discourse-cdn.com/v4/letter/k/e79b87/32.png) [@kjw](https://forum.makecode.com/u/kjw)
#### Post date: [August 23, 2019, 3:43pm UTC](https://forum.makecode.com/t/button-delay-and-repeat-rate/470/1 "2019-08-23T15:43:33Z")

</div>

I’ve just started looking at how the repeat works for the buttons. The `on XX button` block has `pressed`, `released` and `repeat` on it. The first two have obvious semantics but I wasn’t sure how `repeat` worked. In particular, I was concerned that it might be influenced by the settings of the o/s, possibly with per user customisation.

I found there’s a documented part of API for JavaScript programmers. I’m currently trying to stick to Blocks. I wrote some simple code to check the actual values including on PyGamer/Meowbit.

![arcade-Repeat-Rate-v1](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/f614f89ca175630c9968364bda3167e26cf7a120.png)

The values look consistent across simulator (beta beta, `0.14.2 5.21.5`) and hardware which is nice. They also don’t appear to vary based on using mouse vs space bar in sim. Some representative values follow:

```auto
delay: 515
repeat 1: 20
repeat 2: 41
delay: 517
repeat 1: 38
repeat 2: 21
delay: 507
repeat 1: 41
repeat 2: 20

```

I found the docs for [delay](https://arcade.makecode.com/reference/controller/button/repeat-delay) and [interval](https://arcade.makecode.com/reference/controller/button/repeat-interval). It would be useful for those to state the default values in documentation.

From the empirical data it looks like the repeat rate is both not guaranteed and unlikely to consistently match the set rate? Is the granularity the `interval` or 20ms? There’s not much going on in my code at least for first few repeats so I don’t think I can attribute the early jitter here to load from stuff going on in the app?

What’s the philosophy behind these default values? They look like values chosen for typing on a (QUERTY or similar) keyboard but Arcade is a _keyboard-less_ environment. I’m not sure I see the justification for the lengthy `delay` value?

For my intended use I think I need to reduce the `delay` to be the same as the `interval` but I don’t think I can do this in Blocks?

I’d be interested to hear what others think of this feature and how they use it in their Arcade applications.

---

<div class="post-metadata">

### Author: ![jwunderl](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.makecode.com/jwunderl/32/5308_2.png) [@jwunderl](https://forum.makecode.com/u/jwunderl)
#### Post date: [August 23, 2019, 4:19pm UTC](https://forum.makecode.com/t/button-delay-and-repeat-rate/470/2 "2019-08-23T16:19:13Z")

</div>

I added block to set button delay and interval to the controller extension a while back:

 ![Screenshot_20190823-090702_Chrome](https://us1.discourse-cdn.com/flex020/uploads/makecode/original/1X/40b6673537d58ac14f36ab76d2df943bf400df09.jpeg)

The timing for interval will always be approximate - which is also true for `on game update interval`s and other elements. The interval for all these timing based events can be thought of more accurately as a minimum delay before the event will repeat - if you set it to have a repeat interval of 100, it will never occur more than once every 100ms, but may take a bit longer.
