start method

void start(
  1. KeyEvent event, {
  2. bool fast = false,
})

Starts manual repetition for event. Uses a frame-aligned ticker so repetition never exceeds the display refresh rate and cannot starve the compositor thread.

Implementation

void start(KeyEvent event, {bool fast = false}) {
  if (!_active) return;
  stop();
  _lastEvent = event;
  _running = true;

  // Initial delay (same as native key repeat).
  _timer = Timer(_initialDelay, () {
    if (!_running) return;
    _timer = null;

    // Drive repeats with a Ticker that fires once per frame.
    // This guarantees the event rate never exceeds what Flutter can
    // actually render, preventing the 66 Hz timer from flooding the
    // main thread with work faster than it can be painted.
    _ticker = Ticker((_) {
      if (!_running) return;
      final last = _lastEvent;
      if (last != null) _onRepeat(last);
    });
    _ticker!.start();
  });
}