Created
January 29, 2015 17:41
-
-
Save seletskiy/dd7d4e628635c345d376 to your computer and use it in GitHub Desktop.
Calculate your keyboard settings repeat rate (real)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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