From 936e7053ad310585ecbf1f2aceb4fc8b6f6d0e47 Mon Sep 17 00:00:00 2001 From: Metalblueberry Date: Tue, 8 Dec 2020 19:07:40 +0100 Subject: [PATCH] ignore repeat events --- cmd/chkb/main.go | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/cmd/chkb/main.go b/cmd/chkb/main.go index 19c6748..8ef7969 100644 --- a/cmd/chkb/main.go +++ b/cmd/chkb/main.go @@ -4,6 +4,7 @@ import ( "MetalBlueberry/cheap-keyboard/pkg/chkb" "MetalBlueberry/cheap-keyboard/pkg/deliverers/layerFile" "MetalBlueberry/cheap-keyboard/pkg/deliverers/vkb" + "errors" "flag" "fmt" "os" @@ -93,13 +94,19 @@ func main() { if events[i].Type != evdev.EV_KEY { continue } - inputEvents = append(inputEvents, NewKeyInputEvent(events[i])) + ev, err := NewKeyInputEvent(events[i]) + if err != nil { + continue + } + inputEvents = append(inputEvents, ev) } return inputEvents, nil }) } -func NewKeyInputEvent(event evdev.InputEvent) chkb.InputEvent { +var ErrInvalidEvent = errors.New("Invalid event") + +func NewKeyInputEvent(event evdev.InputEvent) (chkb.InputEvent, error) { ie := chkb.InputEvent{ Time: time.Unix(event.Time.Sec, event.Time.Usec*1000), KeyCode: chkb.KeyCode(event.Code), @@ -109,6 +116,8 @@ func NewKeyInputEvent(event evdev.InputEvent) chkb.InputEvent { ie.Action = chkb.InputActionDown case evdev.KeyUp: ie.Action = chkb.InputActionUp + default: + return chkb.InputEvent{}, ErrInvalidEvent } - return ie + return ie, nil }