Documentation ¶
Overview ¶
Package hotkey provides the basic facility to register a system-level hotkey so that the application can be notified if a user triggers the desired hotkey. By definition, a hotkey is a combination of modifiers and a single key, and thus register a hotkey that contains multiple keys is not supported at the moment. Furthermore, because of OS restriction, hotkey events must be handled on the main thread.
Therefore, in order to use this package properly, here is a complete example that corporates the golang.design/x/mainthread package:
package main import ( "context" "golang.design/x/hotkey" "golang.design/x/mainthread" ) // initialize mainthread facility so that hotkey can be // properly registered to the system and handled by the // application. func main() { mainthread.Init(fn) } func fn() { // Use fn as the actual main function. var ( mods = []hotkey.Modifier{hotkey.ModCtrl} k = hotkey.KeyS ) // Register a desired hotkey. hk, err := hotkey.Register(mods, k) if err != nil { panic("hotkey registration failed") } // Start listen hotkey event whenever you feel it is ready. triggered := hk.Listen(context.Background()) for range triggered { println("hotkey ctrl+s is triggered") } }
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Hotkey ¶
type Hotkey struct {
// contains filtered or unexported fields
}
Hotkey is a combination of modifiers and key to trigger an event
type Key ¶
type Key uint8
Key represents a key. See /usr/include/X11/keysymdef.h
const ( Key1 Key = 0x0030 Key2 Key = 0x0031 Key3 Key = 0x0032 Key4 Key = 0x0033 Key5 Key = 0x0034 Key6 Key = 0x0035 Key7 Key = 0x0036 Key8 Key = 0x0037 Key9 Key = 0x0038 Key0 Key = 0x0039 KeyA Key = 0x0061 KeyB Key = 0x0062 KeyC Key = 0x0063 KeyD Key = 0x0064 KeyE Key = 0x0065 KeyF Key = 0x0066 KeyG Key = 0x0067 KeyH Key = 0x0068 KeyI Key = 0x0069 KeyJ Key = 0x006a KeyK Key = 0x006b KeyL Key = 0x006c KeyM Key = 0x006d KeyN Key = 0x006e KeyO Key = 0x006f KeyP Key = 0x0070 KeyQ Key = 0x0071 KeyR Key = 0x0072 KeyS Key = 0x0073 KeyT Key = 0x0074 KeyU Key = 0x0075 KeyV Key = 0x0076 KeyW Key = 0x0077 KeyX Key = 0x0078 KeyY Key = 0x0079 KeyZ Key = 0x007a )
All kinds of keys