Skip to content

Commit

Permalink
Merge pull request #17 from grafov/fix-repeats
Browse files Browse the repository at this point in the history
Correctly print "hold key pressed" events
  • Loading branch information
grafov authored Nov 4, 2023
2 parents fa784da + 67b7190 commit 84b4f5b
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions shift-shift.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,31 @@ func listenKeyboards(

go scanDevices(inbox, deviceMatch, quietMode, scanOnce)

var prevKey evdev.InputEvent
for {
select {
case msg := <-inbox:
for _, ev := range msg.Events {
if ev.Type != evdev.EV_KEY {
continue
}

if prevKey.Code == ev.Code && prevKey.Value == ev.Value && prevKey.Type == ev.Type {
continue
}
prevKey.Type = ev.Type
prevKey.Code = ev.Code
prevKey.Value = ev.Value
if printMode {
pv := "released"
if ev.Value == 1 {
var pv string
switch ev.Value {
case 0:
pv = "released"
case 1:
pv = "pressed"
case 2:
pv = "hold"
default:
pv = "undefined status"
}
log.Printf("%s type:%v code:%v %s", msg.Device.Name, ev.Type, ev.Code, pv)
}
Expand Down

0 comments on commit 84b4f5b

Please sign in to comment.