如何每30秒收集一次击键次数?

我想收集并打印击键次数(NumOfPress),然后每30秒取消一次以获得统计信息。我尝试了许多如何执行重复任务的示例,但每次都失败。我该怎么办?这是我的最新版本的代码:

package main

import (
    "fmt"
    "github.com/kindlyfire/go-keylogger"
    "time"
)

const tm = 30

func tracker (n chan int, f chan float64) {
    kl := keylogger.NewKeylogger()
    NumOfPress := 0
    var freq float64

    for {
        key := kl.GetKey()

        if !key.Empty {
            fmt.Printf("'%c'\n", key.Rune)
            NumOfPress++
        }
        freq = float64(NumOfPress) / float64(tm)
    }
    n <- NumOfPress
    f <- freq
}

func receiver (n chan int, f chan float64) {
    ticker := time.NewTicker(time.Second * tm)
    for _ = range ticker.C {
        fmt.Println("Number of pressings:", <-n)
        fmt.Println("Pressing rate per second:", <-f)
    }
}

func main() {
    var n chan int = make(chan int)
    var f chan float64 = make(chan float64)

    go tracker(n, f)
    go receiver(n, f)

    var input string
    fmt.Scanln(&input)
}