From b2ec95f86d074a98d3436177934f092c76385b2d Mon Sep 17 00:00:00 2001 From: Christian Muehlhaeuser Date: Wed, 9 Feb 2022 07:42:01 +0100 Subject: [PATCH] Don't trigger actions before the key has been released --- main.go | 16 +++------------- 1 file changed, 3 insertions(+), 13 deletions(-) diff --git a/main.go b/main.go index dfba332..6674cef 100644 --- a/main.go +++ b/main.go @@ -115,21 +115,11 @@ func eventLoop(dev *streamdeck.Device, tch chan interface{}) error { if time.Since(keyTimestamps[k.Index]) < longPressDuration { verbosef("Triggering short action for key %d", k.Index) deck.triggerAction(dev, k.Index, false) + } else { + verbosef("Triggering long action for key %d", k.Index) + deck.triggerAction(dev, k.Index, true) } } - if !state && k.Pressed { - // key was pressed - go func() { - // launch timer to observe keystate - time.Sleep(longPressDuration) - - if state, ok := keyStates.Load(k.Index); ok && state.(bool) { - // key still pressed - verbosef("Triggering long action for key %d", k.Index) - deck.triggerAction(dev, k.Index, true) - } - }() - } keyTimestamps[k.Index] = time.Now() case e := <-tch: