# gmouse **Repository Path**: shaoninghouse/gmouse ## Basic Information - **Project Name**: gmouse - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2026-05-19 - **Last Updated**: 2026-05-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # GMouse - 跨平台鼠标控制库 一个纯Go语言实现的跨平台鼠标控制库,支持Windows、Linux和macOS,无需安装任何外部依赖。 ## 特性 - **跨平台支持**:Windows、Linux、macOS 全平台兼容 - **纯Go实现**:无CGO依赖,无外部库依赖 - **简单易用**:简洁的API设计 - **线程安全**:可在多个goroutine中安全使用 ## 安装 ```bash go get gitee.com/shaoninghouse/gmouse ``` ## 使用示例 ```go package main import ( "time" "gitee.com/shaoninghouse/gmouse" ) func main() { // 移动鼠标到指定位置 gmouse.Move(100, 200) // 相对移动 gmouse.MoveRelative(50, 50) // 点击鼠标 gmouse.Click(gmouse.LeftButton) // 左键 gmouse.Click(gmouse.RightButton) // 右键 gmouse.Click(gmouse.MiddleButton) // 中键 // 按下/释放按钮 gmouse.Press(gmouse.LeftButton) time.Sleep(100 * time.Millisecond) gmouse.Release(gmouse.LeftButton) // 获取鼠标当前位置 x, y := gmouse.GetPosition() println("Current position:", x, y) // 滚动鼠标 gmouse.Scroll(0, 1) // 向上滚动 gmouse.Scroll(0, -1) // 向下滚动 gmouse.Scroll(1, 0) // 向右滚动 gmouse.Scroll(-1, 0) // 向左滚动 // 双击 gmouse.DblClick(gmouse.LeftButton) } ``` ## API 文档 ### 移动鼠标 ```go // 移动到绝对坐标 func Move(x, y int) // 相对当前位置移动 func MoveRelative(dx, dy int) ``` ### 鼠标按钮 ```go // 按钮类型 const ( LeftButton = iota RightButton MiddleButton ) // 单击 func Click(button int) // 双击 func DblClick(button int) // 按下 func Press(button int) // 释放 func Release(button int) ``` ### 鼠标位置 ```go // 获取当前鼠标位置 func GetPosition() (x, y int) ``` ### 滚动 ```go // 滚动鼠标,正值向上/右,负值向下/左 func Scroll(dx, dy int) ``` ## 平台实现细节 | 平台 | 实现方式 | |------|----------| | Windows | win32 API (SetCursorPos, mouse_event) | | macOS | CGEvent Quartz API | | Linux | X11 XTest Extension | ## 构建要求 ### Windows ```bash # 安装 MinGW-w64 scoop install gcc # 或 pacman -S mingw-w64-ucrt-x86_64-gcc ``` ### macOS ```bash # 无需额外依赖,系统自带所有框架 export CGO_ENABLED=1 ``` ### Linux ```bash # Debian/Ubuntu sudo apt install libxtst-dev # Fedora/RHEL sudo dnf install libXtst-devel # Arch Linux sudo pacman -S libxtst ``` ### 通用构建命令 ```bash export CGO_ENABLED=1 # macOS 必须 go build -o your_app . ``` ## 许可证 MIT License