Golang监控键盘按键

package main

import (
  "fmt"
  "github.com/go-vgo/robotgo"
  hook "github.com/robotn/gohook"
)

func main() {
  for 1==1 {
      fmt.Println("--- Please press esc ---")
      robotgo.EventHook(hook.KeyDown, []string{"esc"}, func(e hook.Event) {
        fmt.Println("esc")
        robotgo.EventEnd()
      })

      s := robotgo.EventStart()
      <-robotgo.EventProcess(s)

      ok := robotgo.AddEvents("esc")
      if ok {
        fmt.Println("pressed esc...")
      }
  }
}

 

你可能感兴趣的:(Golang,golang)