Skip to content
/ gohook Public

GoHook, Go global keyboard and mouse listener hook

License

Notifications You must be signed in to change notification settings

robotn/gohook

Folders and files

NameName
Last commit message
Last commit date

Latest commit

f049036 · Feb 8, 2025
Aug 26, 2024
May 20, 2020
Feb 9, 2022
Feb 8, 2025
Sep 9, 2021
Feb 19, 2019
Apr 13, 2019
Sep 9, 2021
Feb 8, 2025
Aug 26, 2024
Feb 22, 2020
Jan 2, 2022
Jun 22, 2019
Aug 26, 2024
Aug 26, 2024
Feb 8, 2025
Feb 23, 2020
Mar 3, 2023
Aug 8, 2021

Repository files navigation

gohook

Build Status CircleCI Status Appveyor Go Report Card GoDoc

Requirements (Linux):

Robotgo-requirements-event

Install:

With Go module support (Go 1.11+), just import:

import "github.com/robotn/gohook"

Examples:

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("keyDown: ", "w")
	})

	hook.Register(hook.KeyUp, []string{"w"}, func(e hook.Event) {
		fmt.Println("keyUp: ", "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.