keybind

package module
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Feb 21, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

README

keybind

Keybind is a library to register global OS Hotkeys and associate any function to it.

Simple usage

keys := keybind.StringsToKeys("LALT", "c")
keybind.KeyBind(func() {
    log.Println("hello from key bind - ALT + C")
}, keys...) // Alt, c

keybind.KeyBind(func() {
    log.Println("Ctrl, Alt, c")
}, 162, 164, 67) // Ctrl, Alt, C

keybind.Listen()

for range time.Tick(time.Second) {

}

If the key codes are updated then it *** file should be re generated

  1. go get golang.org/x/tools/cmd/stringer
  2. go generate

Documentation

Index

Constants

View Source
const (
	KeyA uint16 = 4 + iota
	KeyB
	KeyC
	KeyD
	KeyE
	KeyF
	KeyG
	KeyH
	KeyI
	KeyJ
	KeyK
	KeyL
	KeyM
	KeyN
	KeyO
	KeyP
	KeyQ
	KeyR
	KeyS
	KeyT
	KeyU
	KeyV
	KeyW
	KeyX
	KeyY
	KeyZ
)
View Source
const (
	Key1 uint16 = 30 + iota
	Key2
	Key3
	Key4
	Key5
	Key6
	Key7
	Key8
	Key9
	Key0
)
View Source
const (
	// choice is to use Enter name instead of Return
	// and the key code is different from Keypad Enter
	KeyEnter uint16 = 40 + iota
	KeyEscape
	KeyBackspace
	KeyTab
	KeySpace
	// keypad minus has different key code
	KeyMinus
	KeyEquals
	KeyLeftBracket
	KeyRightBracket
	KeyBackslash
)
View Source
const (
	// different name from SDL2 for brevity
	KeyColon uint16 = 51 + iota
	KeyApostrophe
	// KeyTilde is an alias
	KeyGrave
	KeyCommad
	// KeyDot is an alias, keypad period is a different
	KeyPeriod
	Slash
	CapsLock
)
View Source
const (
	KeyF1 uint16 = 58 + iota
	KeyF2
	KeyF3
	KeyF4
	KeyF5
	KeyF6
	KeyF7
	KeyF8
	KeyF9
	KeyF10
	KeyF11
	KeyF12
)
View Source
const (
	KeyPrintScreen uint16 = 70 + iota
	KeyScrollLock
	KeyPause
	KeyInsert
	KeyHome
	KeyPageUp
	KeyDelete
	KeyEnd
	KeyPageDown
	KeyRight
	KeyLeft
	KeyDown
	KeyUp
)
View Source
const (
	KeyNumLock uint16 = 83 + iota
	KeyKpDivide
	KeyKpMultiply
	KeyKpMinus
	KeyKpPlus
	KeyKpEnter
	KeyKp1
	KeyKp2
	KeyKp3
	KeyKp4
	KeyKp5
	KeyKp6
	KeyKp7
	KeyKp8
	KeyKp9
	KeyKp0
	// KeyKpDot is an alias
	KeyKpPeriod
)
View Source
const (
	KeyLCtrl uint16 = 224 + iota
	KeyLShift
	KeyLAlt
	// KeyLWin is an alias
	KeyLGUI
	KeyRCtrl
	KeyRShift
	KeyRAlt
	// KeyRWin is an alias
	KeyRGUI
)
View Source
const KeyDot = KeyPeriod
View Source
const KeyKpDot = KeyKpPeriod
View Source
const KeyLWin = KeyLGUI
View Source
const KeyRWin = KeyRGUI
View Source
const KeyTilde = KeyGrave

Variables

View Source
var (

	// Debug flag (show logs what is pressed)
	Debug = false
)

Functions

func KeyBind

func KeyBind(fn onKeyFunc, keys ...uint16)

KeyBind func

func Liten added in v0.0.3

func Liten()

Liten for registered combinations

func Register added in v0.0.3

func Register(fn onKeyFunc, keys ...KeyCode)

Register keys combination

func ShowRegister added in v0.0.3

func ShowRegister()

ShowRegister func

func StringsToKeys added in v0.0.2

func StringsToKeys(str ...string) []uint16

StringsToKeys func

Types

type KeyCode added in v0.0.3

type KeyCode uint16

KeyCode struct

func (KeyCode) String added in v0.0.3

func (i KeyCode) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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