Files
MyGolandRelease/tools/keys/main.go
T
zerorigin a80c0f886a MyGoland 首次提交:Go 轻量 IDE
- 编辑器:多标签、语法高亮、gopls 全套(补全/诊断/跳转/重命名/代码动作/内联提示/签名大纲)
- 调试:Delve DAP(断点/条件断点/变量树/表达式求值/goroutine 列表)
- 测试:结果树、覆盖率行着色、失败跳源码、-run 精确运行、行号可跑标记
- Git:状态着色、选择性暂存提交、pull/push、历史并排对比
- 本地历史 + 自动快照 + 崩溃恢复、会话/光标恢复
- 全局搜索替换(预览+确认,GBK 安全)、多终端、gopls 崩溃自愈
- 设计文档与验证记录见 docs/plans/
2026-11-04 16:37:05 +08:00

45 lines
1.1 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// keys <socket> <window> <key...>:发送按键(语法同菜单快捷键,如 CmdOrCtrl+P)
package main
import (
"bufio"
"encoding/json"
"fmt"
"net"
"os"
"strconv"
)
func main() {
sock, win := os.Args[1], os.Args[2]
id, _ := strconv.Atoi(win)
c, err := net.Dial("unix", sock)
if err != nil {
fmt.Println("连接失败:", err)
os.Exit(1)
}
defer c.Close()
enc := json.NewEncoder(c)
dec := json.NewDecoder(bufio.NewReader(c))
for _, k := range os.Args[3:] {
var evs []map[string]any
if len(k) > 5 && k[:5] == "text=" {
evs = []map[string]any{{"type": "text", "text": k[5:]}}
} else {
evs = []map[string]any{{"type": "keyDown", "key": k}, {"type": "keyUp", "key": k}}
}
if err := enc.Encode(map[string]any{"id": 1, "method": "input", "params": map[string]any{"window": id, "events": evs}}); err != nil {
fmt.Println("发送失败:", err)
os.Exit(1)
}
var resp struct {
Error any `json:"error"`
}
_ = dec.Decode(&resp)
if resp.Error != nil {
fmt.Printf("失败 %s: %+v\n", k, resp.Error)
}
}
fmt.Println("按键完成")
}