chore: 初始化仓库(零源工具箱 0.1.0 基线)
- Go 主进程 cmd/zerorigin(托盘常驻 + 触发器/规则/动作引擎) - Wails v3 设置进程 cmd/settings(独立 module) - 监督进程 cmd/watchdog(-supervise 异常重启) - 构建脚本 build.bat / NSIS 安装包 deploy/、便携版 portable/ - 架构与 MVP 计划文档 docs/、阶段 0-4 验收记录 deploy/acceptance-0-4.md
This commit is contained in:
commit
0a1c1e82ea
188 files changed
+19926
No files matched your search
@@ -0,0 +1,53 @@
|
||||
package windows
|
||||
|
||||
import (
|
||||
"syscall"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// TestHookReceivesMouseMoveIntegration 真实移动鼠标验证钩子事件流。
|
||||
// 仅在显式启用时运行(默认跳过,避免干扰用户会话)。
|
||||
func TestHookReceivesMouseMoveIntegration(t *testing.T) {
|
||||
if testing.Short() {
|
||||
t.Skip("short mode")
|
||||
}
|
||||
h := NewMouseHook(64)
|
||||
if err := h.Start(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
defer h.Stop()
|
||||
time.Sleep(300 * time.Millisecond)
|
||||
if err := h.InstallErr(); err != nil {
|
||||
t.Fatalf("install: %v", err)
|
||||
}
|
||||
|
||||
// 移动到两个不同位置,确保产生真实移动事件。
|
||||
procSetCursorPos := syscall.NewLazyDLL("user32.dll").NewProc("SetCursorPos")
|
||||
moved := false
|
||||
for _, pos := range [][2]int32{{100, 100}, {400, 300}} {
|
||||
r, _, _ := procSetCursorPos.Call(uintptr(pos[0]), uintptr(pos[1]))
|
||||
if r != 0 {
|
||||
moved = true
|
||||
}
|
||||
time.Sleep(100 * time.Millisecond)
|
||||
}
|
||||
if !moved {
|
||||
t.Skip("session has no active input desktop (e.g. disconnected RDP); physical input unavailable")
|
||||
}
|
||||
|
||||
select {
|
||||
case ev := <-h.Events():
|
||||
t.Logf("received mouse event: msg=%#x pos=(%d,%d)", ev.Message, ev.X, ev.Y)
|
||||
case <-time.After(2 * time.Second):
|
||||
// 区分环境问题(回调从未被调用)与代码问题(回调被调用但事件丢失)。
|
||||
if h.CallbackCalls() == 0 {
|
||||
// SetCursorPos 成功但系统从未回调钩子:无活动输入桌面。
|
||||
procForeground := syscall.NewLazyDLL("user32.dll").NewProc("GetForegroundWindow")
|
||||
fg, _, _ := procForeground.Call()
|
||||
t.Logf("callback calls = 0, foreground=%x", fg)
|
||||
t.Skip("session lacks active input delivery (RDP/headless)")
|
||||
}
|
||||
t.Fatalf("callback called %d times but no event received", h.CallbackCalls())
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user