-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain.go
76 lines (58 loc) · 1.36 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package main
//#include "keyboard.h"
import "C"
import (
"fmt"
"log"
"github.com/lxn/walk"
)
var (
keyNumberPerSecond = 10
)
func main(){
mw, err := walk.NewMainWindow()
if err != nil {
log.Fatal(err)
}
icon, err := walk.Resources.Icon("icon.ico") //walk.NewIconFromResource("icon.ico")
if err != nil {
log.Fatal(err)
}
ni, err := walk.NewNotifyIcon(mw)
if err != nil {
log.Fatal(err)
}
defer ni.Dispose()
if err := ni.SetIcon(icon);err != nil {
log.Fatal(err)
}
//ni.SetToolTip("右键选择不同击键或退出")
for i:=10;i<=20;i+=5 {
action := walk.NewAction()
action.SetText(fmt.Sprintf("击键%d", i))
action.Triggered().Attach(SetKeyTimesFunc(i))
ni.ContextMenu().Actions().Add(action)
}
// We put an exit action into the context menu.
exitAction := walk.NewAction()
if err := exitAction.SetText("E&xit"); err != nil {
log.Fatal(err)
}
exitAction.Triggered().Attach(func() { walk.App().Exit(0) })
if err := ni.ContextMenu().Actions().Add(exitAction); err != nil {
log.Fatal(err)
}
ni.SetVisible(true)
if err := ni.ShowInfo("右键图标选择", "右键图标选择击键(默认10)或退出"); err != nil {
log.Fatal(err)
}
go C.Setup()
// Run the message loop.
mw.Run()
}
func SetKeyTimesFunc(i int) func(){
return func(){
keyNumberPerSecond = i
C.UpdateKeyPressRate(C.int(keyNumberPerSecond));
}
}