hook

package
v0.0.0-...-e2a1ac3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 19, 2020 License: Apache-2.0, GPL-3.0 Imports: 7 Imported by: 0

README

gohook

Build Status CircleCI Status Appveyor Go Report Card GoDoc

package main

import (
	"fmt"

	"github.com/Lemo-yxk/lemo-robot/hook"
)

func main() {
	EvChan := hook.Start()
	defer hook.End()
	
	for ev := range EvChan {
		fmt.Println("hook: ", ev)
	}
}

Based on libuiohook.

Documentation

Index

Constants

View Source
const (
	// Version get the gohook version
	Version = "v0.30.0.80, Sierra Nevada!"

	// HookEnabled honk enable status
	HookEnabled  = 1 // iota
	HookDisabled = 2

	KeyDown = 3
	KeyHold = 4
	KeyUp   = 5

	MouseUp    = 6
	MouseHold  = 7
	MouseDown  = 8
	MouseMove  = 9
	MouseDrag  = 10
	MouseWheel = 11

	FakeEvent = 12
	// Keychar could be v
	CharUndefined = 0xFFFF
	WheelUp       = -1
	WheelDown     = 1
)

Variables

View Source
var Keycode = uMap{
	"`": 41,
	"1": 2,
	"2": 3,
	"3": 4,
	"4": 5,
	"5": 6,
	"6": 7,
	"7": 8,
	"8": 9,
	"9": 10,
	"0": 11,
	"-": 12,
	"+": 13,

	"q":  16,
	"w":  17,
	"e":  18,
	"r":  19,
	"t":  20,
	"y":  21,
	"u":  22,
	"i":  23,
	"o":  24,
	"p":  25,
	"[":  26,
	"]":  27,
	"\\": 43,

	"a": 30,
	"s": 31,
	"d": 32,
	"f": 33,
	"g": 34,
	"h": 35,
	"j": 36,
	"k": 37,
	"l": 38,
	";": 39,
	"'": 40,

	"z": 44,
	"x": 45,
	"c": 46,
	"v": 47,
	"b": 48,
	"n": 49,
	"m": 50,
	",": 51,
	".": 52,
	"/": 53,

	"f1":  59,
	"f2":  60,
	"f3":  61,
	"f4":  62,
	"f5":  63,
	"f6":  64,
	"f7":  65,
	"f8":  66,
	"f9":  67,
	"f10": 68,
	"f11": 69,
	"f12": 70,

	"esc":     1,
	"delete":  14,
	"tab":     15,
	"ctrl":    29,
	"control": 29,
	"alt":     56,
	"space":   57,
	"shift":   42,
	"rshift":  54,
	"enter":   28,

	"cmd":     3675,
	"command": 3675,
	"rcmd":    3676,
	"ralt":    3640,

	"up":    57416,
	"down":  57424,
	"left":  57419,
	"right": 57421,
}

Keycode robotgo hook key's code map

View Source
var MouseMap = uMap{
	"left":       1,
	"right":      2,
	"center":     3,
	"wheelDown":  4,
	"wheelUp":    5,
	"wheelLeft":  6,
	"wheelRight": 7,
}

MouseMap robotgo hook mouse's code map

Functions

func AddEvent

func AddEvent(key string) int

AddEvent add event listener

func End

func End()

End removes global event hook

func KeychartoRawcode

func KeychartoRawcode(kc string) uint16

KeychartoRawcode key char to rawcode

func Process

func Process(EvChan <-chan Event) (out chan bool)

Process return go hook process

func RawcodetoKeychar

func RawcodetoKeychar(r uint16) string

RawcodetoKeychar rawcode to keychar

func Register

func Register(when uint8, cmds []string, cb func(Event))

Register register gohook event

func Start

func Start() chan Event

Start adds global event hook to OS returns event channel

func StopEvent

func StopEvent()

StopEvent stop event listener

Types

type Event

type Event struct {
	Kind     uint8 `json:"id"`
	When     time.Time
	Mask     uint16 `json:"mask"`
	Reserved uint16 `json:"reserved"`

	Keycode uint16 `json:"keycode"`
	Rawcode uint16 `json:"rawcode"`
	Keychar rune   `json:"keychar"`

	Button uint16 `json:"button"`
	Clicks uint16 `json:"clicks"`

	X int16 `json:"x"`
	Y int16 `json:"y"`

	Amount    uint16 `json:"amount"`
	Rotation  int32  `json:"rotation"`
	Direction uint8  `json:"direction"`
}

Event Holds a system event

If it's a Keyboard event the relevant fields are: Mask, Keycode, Rawcode, and Keychar, Keychar is probably what you want.

If it's a Mouse event the relevant fields are: Button, Clicks, X, Y, Amount, Rotation and Direction

func (Event) String

func (e Event) String() string

String return hook kind string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL