@@ -19,41 +19,53 @@ triggers the desired hotkey. A hotkey must be a combination of modifiers
1919and a single key.
2020
2121``` go
22+ package main
23+
2224import (
23- " golang.design/x/hotkey"
24- " golang.design/x/hotkey/mainthread"
25+ " log"
26+
27+ " golang.design/x/hotkey"
28+ " golang.design/x/hotkey/mainthread"
2529)
2630
2731func main () { mainthread.Init (fn) } // Not necessary when use in Fyne, Ebiten or Gio.
2832func fn () {
29- hk := hotkey.New ([]hotkey.Modifier {hotkey.ModCtrl , hotkey.ModShift }, hotkey.KeyS )
30- err := hk.Register ()
31- if err != nil {
32- return
33- }
34- fmt.Printf (" hotkey: %v is registered\n " , hk)
35- <- hk.Keydown ()
36- fmt.Printf (" hotkey: %v is down\n " , hk)
37- <- hk.Keyup ()
38- fmt.Printf (" hotkey: %v is up\n " , hk)
39- hk.Unregister ()
40- fmt.Printf (" hotkey: %v is unregistered\n " , hk)
33+ hk := hotkey.New ([]hotkey.Modifier {hotkey.ModCtrl , hotkey.ModShift }, hotkey.KeyS )
34+ err := hk.Register ()
35+ if err != nil {
36+ log.Fatalf (" hotkey: failed to register hotkey: %v " , err)
37+ return
38+ }
39+
40+ log.Printf (" hotkey: %v is registered\n " , hk)
41+ <- hk.Keydown ()
42+ log.Printf (" hotkey: %v is down\n " , hk)
43+ <- hk.Keyup ()
44+ log.Printf (" hotkey: %v is up\n " , hk)
45+ hk.Unregister ()
46+ log.Printf (" hotkey: %v is unregistered\n " , hk)
4147}
4248```
4349
4450Note platform specific details:
4551
46- - On macOS, due to the OS restriction (other
47- platforms does not have this restriction), hotkey events must be handled
48- on the "main thread". Therefore, in order to use this package properly,
49- one must start an OS main event loop on the main thread, For self-contained
50- applications, using [ golang.design/x/hotkey/mainthread] ( https://pkg.go.dev/golang.design/x/hotkey/mainthread ) is possible.
51- For applications based on other GUI frameworks, such as fyne, ebiten, or Gio.
52- This is not necessary. See the "[ ./examples] ( ./examples ) " folder for more examples.
52+ - On macOS, due to the OS restriction (other platforms does not have this
53+ restriction), hotkey events must be handled on the "main thread".
54+ Therefore, in order to use this package properly, one must start an OS
55+ main event loop on the main thread, For self-contained applications,
56+ using [ golang.design/x/hotkey/mainthread] ( https://pkg.go.dev/golang.design/x/hotkey/mainthread )
57+ is possible. It is uncessary or applications based on other GUI frameworks,
58+ such as fyne, ebiten, or Gio. See the "[ ./examples] ( ./examples ) " folder
59+ for more examples.
5360- On Linux (X11), when AutoRepeat is enabled in the X server, the Keyup
5461 is triggered automatically and continuously as Keydown continues.
55- - If this package did not include a desired key, one can always provide the keycode to the API.
56- For example, if a key code is 0x15, then the corresponding key is ` hotkey.Key(0x15) ` .
62+ - On Linux (X11), some keys may be mapped to multiple Mod keys. To
63+ correctly register the key combination, one must use the correct
64+ underlying keycode combination. For example, a regular Ctrl+Alt+S
65+ might be registered as: Ctrl+Mod2+Mod4+S.
66+ - If this package did not include a desired key, one can always provide
67+ the keycode to the API. For example, if a key code is 0x15, then the
68+ corresponding key is ` hotkey.Key(0x15) ` .
5769
5870## Examples
5971
@@ -65,6 +77,7 @@ Note platform specific details:
6577| A example to use in Fyne | [ fyne] ( ./examples/fyne/main.go ) |
6678| A example to use in Ebiten | [ ebiten] ( ./examples/ebiten/main.go ) |
6779| A example to use in Gio | [ gio] ( ./examples/gio/main.go ) |
80+
6881## Who is using this package?
6982
7083The main purpose of building this package is to support the
0 commit comments