Go lang - 使用 RobotGo 获取当前鼠标光标位置

问题描述 投票:0回答:0

我是围棋初学者,我想解决一个小任务:将鼠标光标的当前坐标打印到控制台,并在鼠标移动时更新它们。为此,我使用了库 robotgo,使用“go get github.com/go-vgo/robotgo”下载它,然后“go get -u github.com/go-vgo/robotgo”,并导入它使用导入“github.com/go-vgo/robotgo”。这是我写的代码:

package main

import (
    "fmt"
    "github.com/go-vgo/robotgo"
)

func main() {
    for {
        x, y := robotgo.GetMousePos()
        fmt.Printf("Current position X=%d, Y=%d", x, y)
        if x == 540 && y == 960 {
            fmt.Println("Cursor @center")
        }

        robotgo.Move(x, y)
    }
}

但我收到错误:

# github.com/robotn/gohook
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:51:10: undefined: addEvent
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:62:7: undefined: Start
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:75:18: undefined: KeyHold
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:83:18: undefined: KeyUp
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:95:22: undefined: KeyUp
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:96:4: undefined: End
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:113:7: undefined: Start
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:121:17: undefined: MouseMove
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:128:22: undefined: MouseDown
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:129:4: undefined: End
C:\CODING\SDK\GO-PATH\pkg\mod\github.com\robotn\[email protected]\event.go:129:4: too many errors

UPD 16.03.2023 问题已通过完全删除库及其依赖项,然后重新安装来解决。

go ide position mouse
© www.soinside.com 2019 - 2024. All rights reserved.