xzkey

package module
v0.0.0-...-fed728d Latest Latest
Warning

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

Go to latest
Published: Feb 4, 2020 License: MIT Imports: 4 Imported by: 4

README

XZ-Key

go语言全局按键监听事件绑定(需要root运行)

依赖

keylogger

案例

...
import xzkey "github.com/CxZMoE/XZ-Key"
...

k := xzkey.NewKeyboard()
if k != nil{
    defer k.StopReadEvent()
    k.BindKeyEvent("sayHallo", func() {
			fmt.Println("Hello")
        }, k.Keys[xzkey.LCTRL], k.Keys[xzkey.LALT], k.Keys[xzkey.H])
        // 按键组合数量没有被限制
    }
}

...

Documentation

Index

Constants

View Source
const (
	NUMLOCK   = "NUMLOCK"
	Q         = "Q"
	W         = "W"
	E         = "E"
	R         = "R"
	T         = "T"
	Y         = "Y"
	U         = "U"
	I         = "I"
	O         = "O"
	P         = "P"
	A         = "A"
	S         = "S"
	D         = "D"
	F         = "F"
	G         = "G"
	H         = "H"
	J         = "J"
	K         = "K"
	L         = "L"
	Z         = "Z"
	X         = "X"
	C         = "C"
	V         = "V"
	B         = "B"
	N         = "N"
	M         = "M"
	UP        = "UP"
	DOWN      = "DOWN"
	LEFT      = "LEFT"
	RIGHT     = "RIGHT"
	PgUp      = "PgUp"
	PgDn      = "PgDn"
	KEY0      = "KEY0"
	KEY1      = "KEY1"
	KEY2      = "KEY2"
	KEY3      = "KEY3"
	KEY4      = "KEY4"
	KEY5      = "KEY5"
	KEY6      = "KEY6"
	KEY7      = "KEY7"
	KEY8      = "KEY8"
	KEY9      = "KEY9"
	BACKSPACE = "BACKSPACE"
	DELETE    = "DELETE"
	INSERT    = "INSERT"
	SPACE     = "SPACE"
	HOME      = "HOME"
	F1        = "F1"
	F2        = "F2"
	F3        = "F3"
	F4        = "F4"
	F5        = "F5"
	F6        = "F6"
	F7        = "F7"
	F8        = "F8"
	F9        = "F9"
	F10       = "F10"
	F11       = "F11"
	F12       = "F12"
	ESC       = "ESC"
	CapsLock  = "CapsLock"
	LSHIFT    = "LSHIFT"
	RSHIFT    = "RSHIFT"
	RCTRL     = "RCTRL"
	LCTRL     = "LCTRL"
	LALT      = "LALT"
	RALT      = "RALT"
	ENTER     = "ENTER"
	TAB       = "TAB"
	KeyOther  = "KeyOther"
	Zkhz      = "["
	Zkhy      = "]"
)

映射

Variables

This section is empty.

Functions

This section is empty.

Types

type Key

type Key struct {
	Pressed  bool // 按住
	Released bool // 松开
}

Key 按键

type KeyBindHandler

type KeyBindHandler interface {
	KeyHandler()
}

KeyBindHandler 键盘事件处理

type Keyboard

type Keyboard struct {
	Keys   map[string]*Key
	Status KeyboardStatus
	Logger *keylogger.KeyLogger
	Event  *chan keylogger.InputEvent
}

Keyboard 键盘

func NewKeyboard

func NewKeyboard() *Keyboard

NewKeyboard 创建一个新键盘

func (*Keyboard) BindKeyEvent

func (k *Keyboard) BindKeyEvent(eventName string, handler func(), keys ...*Key)

BindKeyEvent 绑定按键事件

func (*Keyboard) GetKeyboardDevice

func (k *Keyboard) GetKeyboardDevice() string

GetKeyboardDevice 创建新的键盘设备

func (*Keyboard) Init

func (k *Keyboard) Init() *keylogger.KeyLogger

Init 初始化键盘事件记录对象

func (*Keyboard) MainLoop

func (k *Keyboard) MainLoop()

MainLoop 获取按键状态主循环

func (*Keyboard) StartReadEvent

func (k *Keyboard) StartReadEvent() *chan keylogger.InputEvent

StartReadEvent 开始读取键盘事件

func (*Keyboard) StopReadEvent

func (k *Keyboard) StopReadEvent() error

StopReadEvent 停止读取键盘事件

func (*Keyboard) UnbindKeyEvent

func (k *Keyboard) UnbindKeyEvent(eventName string)

UnbindKeyEvent 解绑按键事件

type KeyboardStatus

type KeyboardStatus struct {
	Device         string // path to dev in /dev/input/eventX
	EventHandlers  map[string]int
	HandleHandlers map[string]func()
}

KeyboardStatus 键盘状态信息

Jump to

Keyboard shortcuts

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