{"record":{"id":"032248356f613702","repo":"m1k1o/neko","slug":"debounced-key-v","errorCode":null,"errorMessage":"debounced key %v","messagePattern":"debounced key (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"info","filePath":"server/pkg/xorg/xorg.go","lineNumber":123,"sourceCode":"\tmu.Lock()\n\tdefer mu.Unlock()\n\n\tif _, ok := debounce_button[code]; ok {\n\t\treturn fmt.Errorf(\"debounced button %v\", code)\n\t}\n\n\tdebounce_button[code] = time.Now()\n\n\tC.XButton(C.uint(code), C.int(1))\n\treturn nil\n}\n\nfunc KeyDown(code uint32) error {\n\tmu.Lock()\n\tdefer mu.Unlock()\n\n\tif _, ok := debounce_key[code]; ok {\n\t\treturn fmt.Errorf(\"debounced key %v\", code)\n\t}\n\n\tdebounce_key[code] = time.Now()\n\n\tC.XKey(C.KeySym(code), C.int(1))\n\treturn nil\n}\n\nfunc ButtonUp(code uint32) error {\n\tmu.Lock()\n\tdefer mu.Unlock()\n\n\tif _, ok := debounce_button[code]; !ok {\n\t\treturn fmt.Errorf(\"debounced button %v\", code)\n\t}\n\n\tdelete(debounce_button, code)\n","sourceCodeStart":105,"sourceCodeEnd":141,"githubUrl":"https://github.com/m1k1o/neko/blob/b0f01cedea68893e85a3fd852c0521238c285695/server/pkg/xorg/xorg.go#L105-L141","documentation":"KeyDown injects an X11 key press and debounces repeats: if the same keysym code is already in debounce_key (pressed recently and not yet released), the call returns 'debounced key %v'. This guards against duplicate keydown injection from autorepeat or retransmission. It is an expected rate-limit rejection.","triggerScenarios":"Calling KeyDown(code) twice without KeyUp(code) between; KeyPress handling an OS autorepeat event for a key already held; duplicated delivery of the same keystroke over the network.","commonSituations":"Holding a key with client-side autorepeat enabled forwarding every repeat to the server; click-spam or key-macro tools issuing rapid repeats; a stale debounce_key entry after a missed KeyUp.","solutions":["Send KeyUp(code) before the next KeyDown(code) for the same key","Disable client-side autorepeat forwarding (only send initial keydown)","Filter duplicate keydown events before calling the API","Treat the error as benign: the key is already pressed"],"exampleFix":"// before\nif err := xorg.KeyDown(key); err != nil { return err }\n// after\nif err := xorg.KeyDown(key); err != nil {\n    if strings.Contains(err.Error(), \"debounced key\") {\n        return nil // autorepeat suppressed by server debounce\n    }\n    return err\n}","handlingStrategy":"validation","validationCode":"// track pressed keys; suppress autorepeat duplicates\nvar pressed = map[uint32]bool{}\nfunc safeKeyDown(code uint32) error {\n    if pressed[code] { return nil }\n    if err := xorg.KeyDown(code); err != nil { return err }\n    pressed[code] = true\n    return nil\n}","typeGuard":"func isDebouncedKey(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"debounced key\")\n}","tryCatchPattern":"if err := xorg.KeyDown(code); err != nil && !isDebouncedKey(err) {\n    return err // ignore expected debounce rejection\n}","preventionTips":["Filter OS autorepeat keydown events before forwarding","Send at most one KeyDown per physical press","Call KeyUp to clear debounce state between repeats","Treat debounce errors as benign no-ops, not failures"],"tags":["input","debounce","keyboard","x11"],"backgroundTag":"debounced-input-event","analyzedSha":"b0f01cedea68893e85a3fd852c0521238c285695","analyzedAt":"2026-09-01T10:35:56.638Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}