-
Notifications
You must be signed in to change notification settings - Fork 942
Open
Description
An error occurred while listening for keyboard events:
My code:
package main
import (
"fmt"
"fyne.io/fyne"
"fyne.io/fyne/app"
"github.com/fyne-io/examples/img/icon"
"github.com/go-vgo/robotgo"
"hchw.com/note/components/input"
)
func main() {
ap := app.New()
hw := ap.NewWindow("hidded")
hw.Hide()
editor := input.NewInputUI()
go listen(ap, editor)
ap.Run()
}
func listen(ap fyne.App,editor fyne.CanvasObject) {
var w fyne.Window
for {
//window.Hide()
show := robotgo.AddEvents("1", "ctrl")
if show {
fmt.Println("pressed ctrl + 1")
if w == nil {
w = ap.NewWindow("Gist Editor")
w.SetContent(editor)
w.Resize(fyne.NewSize(330, 580))
w.SetIcon(icon.TextEditorBitmap)
w.SetOnClosed(func() {
fmt.Println("windows is closed!!!")
w = nil
})
}
w.Show()
w.CenterOnScreen()
}
//time.Sleep(10 * time.Second)
hide := robotgo.AddEvents("2", "ctrl")
if hide {
if w != nil {
fmt.Println("pressed ctrl + 2")
w.Hide()
}
}
}
}Error log:
pressed ctrl + 1
pressed ctrl + 2
pressed ctrl + 1
pressed ctrl + 2
panic: send on closed channel
goroutine 14 [running]:
github.com/robotn/gohook.go_send(0x28f43650)
C:/code/gowork/pkg/mod/github.com/robotn/[email protected]/extern.go:39 +0x253
github.com/robotn/gohook._cgoexpwrap_07287e64bee3_go_send(0x28f43650)
_cgo_gotypes.go:144 +0x32
github.com/robotn/gohook._Cfunc_pollEv()
_cgo_gotypes.go:104 +0x48
github.com/robotn/gohook.Start.func1()
C:/code/gowork/pkg/mod/github.com/robotn/[email protected]/hook.go:233 +0x2b
created by github.com/robotn/gohook.Start
C:/code/gowork/pkg/mod/github.com/robotn/[email protected]/hook.go:227 +0x8d
exit status 2