Skip to content

Commit 6a23bc9

Browse files
committed
all: improve documentation
Fixes #17
1 parent 827d2c9 commit 6a23bc9

File tree

5 files changed

+620
-347
lines changed

5 files changed

+620
-347
lines changed

README.md

Lines changed: 36 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -19,41 +19,53 @@ triggers the desired hotkey. A hotkey must be a combination of modifiers
1919
and a single key.
2020

2121
```go
22+
package main
23+
2224
import (
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

2731
func main() { mainthread.Init(fn) } // Not necessary when use in Fyne, Ebiten or Gio.
2832
func 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

4450
Note 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

7083
The main purpose of building this package is to support the

examples/go.mod

Lines changed: 36 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,51 @@
11
module golang.design/x/hotkey/examples
22

3-
go 1.17
3+
go 1.19
44

55
require (
6-
fyne.io/fyne/v2 v2.1.2
7-
gioui.org v0.0.0-20220104172405-7751d737403e
8-
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20211213063430-748e38ca8aec
9-
github.com/hajimehoshi/ebiten/v2 v2.3.0-alpha.4.0.20220103082943-8418c4a65551
10-
golang.design/x/hotkey v0.2.1
6+
fyne.io/fyne/v2 v2.3.0
7+
gioui.org v0.0.0-20221223153152-aa2a948b863a
8+
github.com/go-gl/glfw/v3.3/glfw v0.0.0-20221017161538-93cebf72946b
9+
github.com/hajimehoshi/ebiten/v2 v2.4.15
10+
golang.design/x/hotkey v0.4.0
1111
)
1212

1313
require (
14+
fyne.io/systray v1.10.1-0.20221115204952-d16a6177e6f1 // indirect
1415
gioui.org/cpu v0.0.0-20210817075930-8d6a761490d2 // indirect
1516
gioui.org/shader v1.0.6 // indirect
17+
github.com/benoitkugler/textlayout v0.3.0 // indirect
1618
github.com/davecgh/go-spew v1.1.1 // indirect
17-
github.com/fredbi/uri v0.0.0-20181227131451-3dcfdacbaaf3 // indirect
18-
github.com/fsnotify/fsnotify v1.4.9 // indirect
19-
github.com/go-gl/gl v0.0.0-20210813123233-e4099ee2221f // indirect
20-
github.com/godbus/dbus/v5 v5.0.4 // indirect
21-
github.com/goki/freetype v0.0.0-20181231101311-fa8a33aabaff // indirect
22-
github.com/jezek/xgb v0.0.0-20210312150743-0e0f116e1240 // indirect
19+
github.com/ebitengine/purego v0.0.0-20220905075623-aeed57cda744 // indirect
20+
github.com/fredbi/uri v0.1.0 // indirect
21+
github.com/fsnotify/fsnotify v1.5.4 // indirect
22+
github.com/fyne-io/gl-js v0.0.0-20220119005834-d2da28d9ccfe // indirect
23+
github.com/fyne-io/glfw-js v0.0.0-20220120001248-ee7290d23504 // indirect
24+
github.com/fyne-io/image v0.0.0-20220602074514-4956b0afb3d2 // indirect
25+
github.com/go-gl/gl v0.0.0-20211210172815-726fda9656d6 // indirect
26+
github.com/go-text/typesetting v0.0.0-20221214153724-0399769901d5 // indirect
27+
github.com/godbus/dbus/v5 v5.1.0 // indirect
28+
github.com/goki/freetype v0.0.0-20220119013949-7a161fd3728c // indirect
29+
github.com/gopherjs/gopherjs v1.17.2 // indirect
30+
github.com/hajimehoshi/file2byteslice v0.0.0-20210813153925-5340248a8f41 // indirect
31+
github.com/jezek/xgb v1.0.1 // indirect
32+
github.com/jsummers/gobmp v0.0.0-20151104160322-e2ba15ffa76e // indirect
2333
github.com/pmezard/go-difflib v1.0.0 // indirect
24-
github.com/srwiley/oksvg v0.0.0-20200311192757-870daf9aa564 // indirect
25-
github.com/srwiley/rasterx v0.0.0-20200120212402-85cb7272f5e9 // indirect
26-
github.com/stretchr/testify v1.7.0 // indirect
27-
github.com/yuin/goldmark v1.4.0 // indirect
34+
github.com/srwiley/oksvg v0.0.0-20220731023508-a61f04f16b76 // indirect
35+
github.com/srwiley/rasterx v0.0.0-20210519020934-456a8d69b780 // indirect
36+
github.com/stretchr/testify v1.8.0 // indirect
37+
github.com/tevino/abool v1.2.0 // indirect
38+
github.com/yuin/goldmark v1.4.13 // indirect
2839
golang.design/x/mainthread v0.3.0 // indirect
29-
golang.org/x/exp v0.0.0-20210722180016-6781d3edade3 // indirect
30-
golang.org/x/image v0.0.0-20210628002857-a66eb6448b8d // indirect
31-
golang.org/x/mobile v0.0.0-20210902104108-5d9a33257ab5 // indirect
32-
golang.org/x/net v0.0.0-20210805182204-aaa1db679c0d // indirect
33-
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c // indirect
34-
golang.org/x/sys v0.0.0-20210917161153-d61c044b1678 // indirect
35-
golang.org/x/text v0.3.6 // indirect
36-
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
40+
golang.org/x/exp v0.0.0-20221012211006-4de253d81b95 // indirect
41+
golang.org/x/exp/shiny v0.0.0-20220827204233-334a2380cb91 // indirect
42+
golang.org/x/image v0.1.0 // indirect
43+
golang.org/x/mobile v0.0.0-20220722155234-aaac322e2105 // indirect
44+
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
45+
golang.org/x/sys v0.0.0-20220825204002-c680a09ffe64 // indirect
46+
golang.org/x/text v0.4.0 // indirect
47+
gopkg.in/yaml.v3 v3.0.1 // indirect
48+
honnef.co/go/js/dom v0.0.0-20210725211120-f030747120f2 // indirect
3749
)
3850

3951
replace golang.design/x/hotkey => ../

0 commit comments

Comments
 (0)