本程序采用github.com/lxn/walk的walk.WebView实现一个GUI程序,启动一个http server,GUI访问本地http server。
支持写日志、响应键盘事件等。
完整代码:
main.go
//先安装mingw64
package main
import (
"os"
"strings"
"time"
"github.com/go-vgo/robotgo"
"github.com/lxn/walk"
. "github.com/lxn/walk/declarative"
hook "github.com/robotn/gohook"
)
//写日志
func WriteLog(str_content string) {
fd, _ := os.OpenFile("./log.txt", os.O_RDWR|os.O_CREATE|os.O_APPEND, 0644)
fd_time := time.Now().Format("2006-01-02 15:04:05")
fd_content := strings.Join([]string{fd_time, ": ", str_content, "\n"}, "")
buf := []byte(fd_content)
fd.Write(buf)
fd.Close()
}
//响应键盘事件
func KeyEvent() {
for 1 == 1 {
robotgo.EventHook(hook.KeyDown, []string{"esc"}, func(e hook.Event) {
if isFullScreen {
NormalScreen()
}else{
FullScreen()
}
robotgo.EventEnd()
})
s := robotgo.EventStart()
<-robotgo.EventProcess(s)
ok := robotgo.AddEvents("esc")
if ok {
//WriteLog("Add


2330

被折叠的 条评论
为什么被折叠?



