robotn/gohook: GoHook, Go global keyboard and mouse listener hook
2020-11-22 19:08:50 Author: github.com(查看原文) 阅读量:332 收藏

Build Status CircleCI Status Appveyor Go Report Card GoDoc

package main

import (
	"fmt"

	hook "github.com/robotn/gohook"
)

func main() {
	add()

	low()
}

func add() {
	fmt.Println("--- Please press ctrl + shift + q to stop hook ---")
	hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) {
		fmt.Println("ctrl-shift-q")
		hook.End()
	})

	fmt.Println("--- Please press w---")
	hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) {
		fmt.Println("w")
	})

	s := hook.Start()
	<-hook.Process(s)
}

func low() {
	EvChan := hook.Start()
	defer hook.End()

	for ev := range EvChan {
		fmt.Println("hook: ", ev)
	}
}

Based on libuiohook.


文章来源: https://github.com/robotn/gohook
如有侵权请联系:admin#unsafe.sh