43 lines
712 B
Go
43 lines
712 B
Go
package src
|
|
|
|
import (
|
|
"context"
|
|
"mayhem-party/src/device/input"
|
|
"mayhem-party/src/device/output"
|
|
"mayhem-party/src/device/output/key"
|
|
"time"
|
|
)
|
|
|
|
func Main(ctx context.Context) error {
|
|
reader := input.New()
|
|
writer := output.New()
|
|
c := time.NewTicker(time.Millisecond * 50)
|
|
defer c.Stop()
|
|
|
|
block := func() bool {
|
|
select {
|
|
case <-c.C:
|
|
return true
|
|
case <-ctx.Done():
|
|
return false
|
|
}
|
|
}
|
|
|
|
state := map[key.Key]bool{}
|
|
for block() {
|
|
delta := reader.Read()
|
|
for _, button := range delta {
|
|
state[key.FromChar(button.Char)] = button.Down
|
|
}
|
|
keys := make([]key.Key, 0)
|
|
for k, v := range state {
|
|
if v {
|
|
keys = append(keys, k)
|
|
}
|
|
}
|
|
writer.Press(keys...)
|
|
}
|
|
|
|
return ctx.Err()
|
|
}
|