func (c *Captor) Run(capture CaptureFunc, send MapFunc) error {
	for {
		err := c.loop(capture, send)
		if err != nil {
			return err
		}
	}
}
Run creates a capture infinite loop, The loop will call capture function to get the input events
and call send function when it captures something.
capture should block is new data is not available.
send can be called from different gorouties but will not perform calls in parallel.
package chkb
import (
	"sync"
	"time"
	"github.com/benbjohnson/clock"
	log "github.com/sirupsen/logrus"
)
type Captor struct {
	Clock  clock.Clock
	Config *Config
	idleTimers map[KeyCode]*idleTimer
	lastKey    *idleTimer
	m          sync.Mutex
}
func NewCaptor(config *Config) *Captor {
	return NewCaptorWithClock(clock.New(), config)
}
func NewCaptorWithClock(clock clock.Clock, config *Config) *Captor {
	return &Captor{
		Clock:      clock,
		Config:     config,
		idleTimers: make(map[KeyCode]*idleTimer),
		m:          sync.Mutex{},
	}
}
type idleTimer struct {
	Timeout *clock.Timer
	Time    time.Time
	Count   int
	KeyCode KeyCode
}
func (c *Captor) newIdleTimer(keyCode KeyCode, send MapFunc) *idleTimer {
	timer := &idleTimer{
		Timeout: c.Clock.AfterFunc(c.Config.GetTapDelay(), c.idle(keyCode, send)),
		KeyCode: keyCode,
	}
	timer.Timeout.Stop()
	c.idleTimers[keyCode] = timer
	return timer
}
type InputEvent struct {
	Time    time.Time
	KeyCode KeyCode
	Action  InputActions
}
type InputActions int
const (
	InputActionNil InputActions = iota
	InputActionDown
	InputActionUp
)
type MapFunc func([]KeyEvent) error
type CaptureFunc func() ([]InputEvent, error)
func (c *Captor) loop(capture CaptureFunc, send MapFunc) error {
	events, err := capture()
	if err != nil {
		log.WithError(err).Error("cannot capture more events")
		return err
	}
	c.m.Lock()
	defer c.m.Unlock()
	captured, err := c.capture(events)
	if err != nil {
		log.WithError(err).Error("Cannot capture events")
		return err
	}
	for _, event := range captured {
		timer, ok := c.idleTimers[event.KeyCode]
		switch event.Action {
		case KeyActionDown:
			if !ok {
				timer = c.newIdleTimer(event.KeyCode, send)
			}
			if timer.Timeout.Stop() {
				timer.Count++
			} else {
				timer.Count = 0
			}
			timer.Timeout.Reset(c.Config.GetTapDelay())
			timer.Time = event.Time
			if c.lastKey != nil && c.lastKey != timer {
				if c.lastKey.Timeout.Stop() {
					c.deliverEvent(c.lastKey, send)
				}
			}
		case KeyActionUp:
			if ok {
				if timer.Timeout.Stop() {
					timer.Count++
					timer.Timeout.Reset(c.Config.GetTapDelay())
					timer.Time = event.Time
				}
			}
		}
		if timer != nil {
			c.lastKey = timer
		}
	}
	return send(captured)
}