酷代码 AI
菜单
服务商
DeepSeek字节豆包讯飞星火
更多选项

Go语言:Windows平台下轻松实现鼠标位置获取(附代码)

以下是一个使用 Go 语言在 Windows 平台上获取鼠标位置的示例代码,需要安装 `github.com/lxn/win` 库: ```go package main import ( "fmt" "github.com/lxn/win" ) func getMousePosition() (int, int) { pt := win.POINT{} if win.GetCursorPos(&pt) { return int(pt.X), int(pt.Y) } return -1, -1 } func main() { x, y := getMousePosition() if x!= -1 && y!= -1 { fmt.Printf("鼠标当前位置: X=%d, Y=%d\n", x, y) } else { fmt.Println("获取鼠标位置失败") } } ``` 上述代码仅在 Windows 平台上有效。在其他操作系统上,获取鼠标位置的方式可能会有所不同。 ######[AI写代码神器 | 216点数解答 | 2024-11-04 10:53:31]

相关提问
本站限时免费提问中
实用工具查看更多
Linux在线手册 [开发类]
Jquery在线手册 [开发类]
今日油价 [生活类]
图片互转base64 [开发类]
时间转换器 [开发类]