⌨️ cross-platform hotkey package
cross platform hotkey package in Go
import "golang.design/x/hotkey"
Package hotkey provides the basic facility to register a system-level
global hotkey shortcut so that an application can be notified if a user
triggers the desired hotkey. A hotkey must be a combination of modifiers
and a single key.
package main
import (
"log"
"golang.design/x/hotkey"
"golang.design/x/hotkey/mainthread"
)
func main() { mainthread.Init(fn) } // Not necessary when use in Fyne, Ebiten or Gio.
func fn() {
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS)
err := hk.Register()
if err != nil {
log.Fatalf("hotkey: failed to register hotkey: %v", err)
return
}
log.Printf("hotkey: %v is registered\n", hk)
<-hk.Keydown()
log.Printf("hotkey: %v is down\n", hk)
<-hk.Keyup()
log.Printf("hotkey: %v is up\n", hk)
hk.Unregister()
log.Printf("hotkey: %v is unregistered\n", hk)
}
Note platform specific details:
hotkey.Key(0x15)
.Description | Folder |
---|---|
A minimum example | minimum |
Register multiple hotkeys | multiple |
A example to use in GLFW | glfw |
A example to use in Fyne | fyne |
A example to use in Ebiten | ebiten |
A example to use in Gio | gio |
The main purpose of building this package is to support the
midgard project.
To know more projects, check our wiki page.
MIT | © 2021 The golang.design Initiative Authors, written by Changkun Ou.