-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.go
139 lines (129 loc) · 3.67 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
package main
import (
"time"
"github.com/gen2brain/beeep"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
)
func main() {
var value *walk.TextEdit
var hotkeyLabel *walk.Label
var slider *walk.Slider
var mainWnd *walk.MainWindow
var sendEnter *walk.CheckBox
defaultBinding, err := SetNewBinding([]int{0, 1}, 10)
if err != nil {
walk.MsgBox(nil, "Failed to bind a default hotkey", err.Error()+"\nTry to change the hotkey to something another", walk.MsgBoxApplModal)
}
go func() {
ListenForHotkey(func() {
time.Sleep(time.Millisecond * 150)
valueToWrite := value.Text()
if len(valueToWrite) == 0 {
return
}
beeep.Beep(beeep.DefaultFreq*2, beeep.DefaultDuration/4) // emulate scanner sound :)
EmulateTyping(valueToWrite, slider.Value(), sendEnter.CheckState() == walk.CheckChecked)
})
}() // listen in bg, non-blocking the main GUI thread
ico, err := walk.NewIconFromResourceId(2) // icon id from manifest
if err != nil {
panic("could not load icon")
}
MainWindow{
AssignTo: &mainWnd,
Title: "Barcode Reader Emulator",
Size: Size{Width: 350, Height: 135},
Icon: ico,
Layout: VBox{},
Children: []Widget{
HSplitter{
Children: []Widget{
Label{Text: "Value"},
TextEdit{
AssignTo: &value,
Text: "test",
MaxLength: 128,
CompactHeight: true,
VScroll: true,
},
PushButton{
Text: "Scan from the screen",
MaxSize: Size{Width: 40, Height: 20},
OnClicked: func() {
val, err := ScanScreenBarcode()
if err != nil {
walk.MsgBox(mainWnd, "Failed to scan", "Could not find or parse a barcode. Try to zoom in a bit or choose another one.\nParser error: "+err.Error(), walk.MsgBoxApplModal)
} else {
value.SetText(val)
}
},
},
},
},
HSplitter{
Children: []Widget{
Label{Text: "Hotkey"},
Label{AssignTo: &hotkeyLabel, Text: defaultBinding},
PushButton{
Text: "Change",
MaxSize: Size{Width: 40, Height: 20},
OnClicked: func() {
var lb *walk.ListBox
var cb *walk.ComboBox
var dlg *walk.Dialog
modLabels := make([]string, len(AllModifiers))
for i := 0; i < len(AllModifiers); i++ {
modLabels[i] = modifierToString(AllModifiers[i])
}
hotkeyLabels := make([]string, len(AllHotkeys))
for i := 0; i < len(AllHotkeys); i++ {
hotkeyLabels[i] = hotkeyToString(AllHotkeys[i])
}
Dialog{
AssignTo: &dlg,
Title: "Select a new hotkey",
Layout: HBox{},
MinSize: Size{Width: 250, Height: 110},
Children: []Widget{
ListBox{
AssignTo: &lb,
MultiSelection: true,
Model: modLabels,
},
ComboBox{
Model: hotkeyLabels,
AssignTo: &cb,
CurrentIndex: 0,
},
PushButton{Text: "OK", OnClicked: func() {
selModIdx := lb.SelectedIndexes()
selHotkeyIdx := cb.CurrentIndex()
bindingLabel, err := SetNewBinding(selModIdx, selHotkeyIdx)
if err != nil {
walk.MsgBox(mainWnd, "Failed", err.Error(), walk.MsgBoxApplModal)
} else {
hotkeyLabel.SetText(bindingLabel)
dlg.Close(walk.DlgCmdOK)
}
}},
},
}.Run(mainWnd)
},
},
},
},
HSplitter{
Children: []Widget{
Label{Text: "Input Key Delay"},
Slider{AssignTo: &slider, MinValue: 10, MaxValue: 100},
CheckBox{
Text: "Send ENTER at the end",
AssignTo: &sendEnter,
MinSize: Size{Width: 40, Height: 20},
},
},
},
},
}.Run()
}