Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delay before repeat (ala keypress repeat delay) #30

Open
dansteingart opened this issue Jan 2, 2022 · 1 comment
Open

Delay before repeat (ala keypress repeat delay) #30

dansteingart opened this issue Jan 2, 2022 · 1 comment

Comments

@dansteingart
Copy link

Is there a simple way of implementing a hold delay, such that the following behavior happens:

  1. On button press: single event,
  2. then if held an X ms delay before it repeats.

Similar to a keyboard repeat delay. TIA.

@vdegenne
Copy link

vdegenne commented Feb 13, 2023

@dansteingart I don't think there is a way implemented but you can implement it yourself such easily, e.g.

// time to wait before repeating key
const repeatAfterMs = 1000 // 1s
// repeat speed
const repeatSpeedMs = 300 // 0.3s

let repeatStartTimeout, repeatInterval

gamepad
.before('button0', () => {
  action()
  repeatStartTimeout = setTimeout(() => {
    repeatInterval = setInterval(() => {
      action()
    }, repeatSpeedMs)
  }, repeatAfterMs)
})
.after('button0', () => {
  clearTimeout(repeatStartTimeout)
  clearInterval(repeatInterval)
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants