-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
main.go
34 lines (29 loc) · 922 Bytes
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
// Copyright 2022 The golang.design Initiative Authors.
// All rights reserved. Use of this source code is governed
// by a MIT license that can be found in the LICENSE file.
package main
import (
"fyne.io/fyne/v2"
"fyne.io/fyne/v2/app"
"fyne.io/fyne/v2/container"
"fyne.io/fyne/v2/widget"
"golang.design/x/hotkey"
)
func main() {
w := app.New().NewWindow("golang.design/x/hotkey")
label := widget.NewLabel("Hello golang.design!")
button := widget.NewButton("Hi!", func() { label.SetText("Welcome :)") })
w.SetContent(container.NewVBox(label, button))
go func() {
// Register a desired hotkey.
hk := hotkey.New([]hotkey.Modifier{hotkey.ModCtrl, hotkey.ModShift}, hotkey.KeyS)
if err := hk.Register(); err != nil {
panic("hotkey registration failed")
}
// Start listen hotkey event whenever it is ready.
for range hk.Keydown() {
button.Tapped(&fyne.PointEvent{})
}
}()
w.ShowAndRun()
}