Skip to content

Commit 258b6bc

Browse files
committed
examples: add minimum
1 parent 9afab3a commit 258b6bc

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

examples/minimum/main.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright 2021 The golang.design Initiative Authors.
2+
// All rights reserved. Use of this source code is governed
3+
// by a MIT license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"golang.design/x/hotkey"
9+
"golang.design/x/hotkey/mainthread"
10+
)
11+
12+
func main() { mainthread.Init(fn) }
13+
func fn() {
14+
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl}, hotkey.KeyS)
15+
var err error
16+
if mainthread.Call(func() { err = hk.Register() }); err != nil {
17+
panic(err)
18+
}
19+
20+
for range hk.Keydown() {
21+
println("hotkey ctrl+s is triggered, exit the application, good bye!")
22+
hk.Unregister()
23+
}
24+
}

0 commit comments

Comments
 (0)