Skip to content

Instantly share code, notes, and snippets.

@seletskiy
Created January 29, 2015 17:41
Show Gist options
  • Select an option

  • Save seletskiy/dd7d4e628635c345d376 to your computer and use it in GitHub Desktop.

Select an option

Save seletskiy/dd7d4e628635c345d376 to your computer and use it in GitHub Desktop.
Calculate your keyboard settings repeat rate (real)
package main
import (
"fmt"
"os"
"os/exec"
"time"
)
func main() {
// disable input buffering
exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
// do not display entered characters on the screen
exec.Command("stty", "-F", "/dev/tty", "-echo").Run()
fmt.Println("Just hold key to count keypresses")
counter := 0
go func() {
t := time.NewTicker(time.Second * 1)
for {
<-t.C
if counter > 0 {
fmt.Printf(" [%d]\n", counter)
}
counter = 0
}
}()
b := []byte{0}
for {
os.Stdin.Read(b)
fmt.Print(string(b))
counter++
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment