### Install Robotgo Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Use 'go get' to install the Robotgo library. This command fetches and installs the package and its dependencies. ```bash go get -u github.com/go-vgo/robotgo ``` -------------------------------- ### Install Go Clipboard Library Source: https://github.com/go-vgo/robotgo/blob/master/clipboard/README.md Use 'go get' to install the clipboard library for your Go project. This command fetches and installs the package. ```bash $ go get github.com/atotto/clipboard ``` -------------------------------- ### Install Golang on Windows Source: https://github.com/go-vgo/robotgo/blob/master/README.md Use winget to install the official Golang package on Windows. ```bash winget install Golang.go ``` -------------------------------- ### Mouse Control Example Source: https://github.com/go-vgo/robotgo/blob/master/README.md Demonstrates various mouse operations including moving, scrolling, clicking, and dragging. Supports multi-screen setups. ```go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { robotgo.MouseSleep = 300 robotgo.Move(100, 100) fmt.Println(robotgo.Location()) robotgo.Move(100, -200) // multi screen supported robotgo.MoveSmooth(120, -150) fmt.Println(robotgo.Location()) robotgo.ScrollDir(10, "up") robotgo.ScrollDir(20, "right") robotgo.Scroll(0, -10) robotgo.Scroll(100, 0) robotgo.MilliSleep(100) robotgo.ScrollSmooth(-10, 6) // robotgo.ScrollRelative(10, -100) robotgo.Move(10, 20) robotgo.MoveRelative(0, -10) robotgo.DragSmooth(10, 10) robotgo.Click("wheelRight") robotgo.Click("left", true) robotgo.MoveSmooth(100, 200, 1.0, 10.0) robotgo.Toggle("left") robotgo.Toggle("left", "up") } ``` -------------------------------- ### Install Gocopy Command-Line Tool Source: https://github.com/go-vgo/robotgo/blob/master/clipboard/README.md Install the 'gocopy' command-line tool using 'go get'. This tool can be used to copy content from standard input to the clipboard. ```bash $ go get github.com/atotto/clipboard/cmd/gocopy $ # example: $ cat document.txt | gocopy ``` -------------------------------- ### Install Gopaste Command-Line Tool Source: https://github.com/go-vgo/robotgo/blob/master/clipboard/README.md Install the 'gopaste' command-line tool using 'go get'. This tool can be used to paste content from the clipboard to standard output. ```bash $ go get github.com/atotto/clipboard/cmd/gopaste $ # example: $ gopaste > document.txt ``` -------------------------------- ### Keyboard Control Example Source: https://github.com/go-vgo/robotgo/blob/master/README.md Shows how to type text, including Unicode characters, and simulate key presses and toggles. Includes reading clipboard content. ```go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { robotgo.Type("Hello World") robotgo.Type("だんしゃり", 0, 1) // robotgo.Type("テストする") robotgo.Type("Hi, Seattle space needle, Golden gate bridge, One world trade center.") robotgo.Type("Hi galaxy, hi stars, hi MT.Rainier, hi sea. こんにちは世界.") robotgo.Sleep(1) // ustr := uint32(robotgo.CharCodeAt("Test", 0)) // robotgo.UnicodeType(ustr) robotgo.KeySleep = 100 robotgo.KeyTap("enter") // robotgo.Type("en") robotgo.KeyTap("i", "alt", "cmd") arr := []string{"alt", "cmd"} robotgo.KeyTap("i", arr) robotgo.MilliSleep(100) robotgo.KeyToggle("a") robotgo.KeyToggle("a", "up") robotgo.WriteAll("Test") text, err := robotgo.ReadAll() if err == nil { fmt.Println(text) } } ``` -------------------------------- ### Install Mingw-w64 on Windows Source: https://github.com/go-vgo/robotgo/blob/master/README.md Install Mingw-w64 for Windows using winget. Alternatively, download from SourceForge and set system environment variables. ```bash winget install BrechtSanders.WinLibs.POSIX.UCRT ``` ```bash C:\mingw64\bin ``` -------------------------------- ### Install X11 Dependencies on Ubuntu Source: https://github.com/go-vgo/robotgo/blob/master/README.md Install necessary X11 development libraries and tools on Ubuntu for Robotgo functionality. ```bash sudo apt install gcc libc6-dev # x11 sudo apt install libx11-dev xorg-dev libxtst-dev # Clipboard sudo apt install xsel xclip # Bitmap sudo apt install libpng++-dev # GoHook sudo apt install xcb libxcb-xkb-dev x11-xkb-utils libx11-xcb-dev libxkbcommon-x11-dev libxkbcommon-dev ``` -------------------------------- ### Install LLVM-MinGW on Windows Source: https://github.com/go-vgo/robotgo/blob/master/README.md Install LLVM-MinGW for Windows using winget. This is an alternative to Mingw-w64. ```bash winget install MartinStorsjo.LLVM-MinGW.UCRT ``` -------------------------------- ### Install Golang and GCC Source: https://github.com/go-vgo/robotgo/blob/master/README.md Ensure Golang and GCC are installed correctly before installing RobotGo. For macOS, Homebrew can be used to install Go. ```bash Golang GCC ``` ```bash brew install go ``` -------------------------------- ### Install X11 Dependencies on Fedora Source: https://github.com/go-vgo/robotgo/blob/master/README.md Install necessary X11 development libraries and tools on Fedora for Robotgo functionality. ```bash sudo dnf install libXtst-devel # Clipboard sudo dnf install xsel xclip # Bitmap sudo dnf install libpng-devel ``` -------------------------------- ### Cross-Compiler GCC/G++ Paths (Commented) Source: https://github.com/go-vgo/robotgo/blob/master/docs/install.md Commented-out example paths for MinGW-w64 GCC and G++ compilers, useful for debugging or specifying custom toolchain locations. ```bash // CC=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\gcc.exe // CXX=mingw-w64\x86_64-7.2.0-win32-seh-rt_v5-rev1\mingw64\bin\g++.exe ``` -------------------------------- ### Install Cross-Compilation Requirements on Ubuntu Source: https://github.com/go-vgo/robotgo/blob/master/docs/install.md Install necessary GCC toolchains and libraries for cross-compiling to Windows on a Debian-based system like Ubuntu. Includes fixing zlib.h errors. ```bash sudo apt install gcc-multilib sudo apt install gcc-mingw-w64 # fix err: zlib.h: No such file or directory, Just used by bitmap. sudo apt install libz-mingw-w64-dev ``` -------------------------------- ### Build Commands for RobotGo Source: https://github.com/go-vgo/robotgo/blob/master/AGENTS.md Common commands for building, testing, and formatting the RobotGo project. Ensure GCC is installed and CGO_ENABLED is set to 1. ```bash go build -v . ``` ```bash go build -v ./... ``` ```bash go get -v -t -d ./... ``` ```bash go test -v robot_info_test.go ``` ```bash go test -v ./... ``` ```bash go test -v -run TestGetScreenSize . ``` ```bash gofmt -w . ``` ```bash go vet ./... ``` ```bash cd examples/mouse && go run main.go ``` -------------------------------- ### Manage Windows and Show Alerts Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Finds window process IDs by title, activates a window by PID or name, checks if a PID exists, kills a process, displays an alert box, and gets the current window title. Requires importing 'fmt' and 'robotgo'. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { fpid, err := robotgo.FindIds("Google") if err == nil { fmt.Println("pids...", fpid) if len(fpid) > 0 { robotgo.ActivePID(fpid[0]) robotgo.Kill(fpid[0]) } } robotgo.ActiveName("chrome") isExist, err := robotgo.PidExists(100) if err == nil && isExist { fmt.Println("pid exists is", isExist) robotgo.Kill(100) } abool := robotgo.ShowAlert("test", "robotgo") if abool == 0 { fmt.Println("ok@@@", "ok") } title := robotgo.GetTitle() fmt.Println("title@@@", title) } ``` -------------------------------- ### Get Screen Pixel Color and Position Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Retrieves the current mouse cursor position and the color of a pixel at specified coordinates. Requires importing 'fmt' and 'robotgo'. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { x, y := robotgo.Location() fmt.Println("pos:", x, y) color := robotgo.GetPixelColor(100, 200) fmt.Println("color----", color) } ``` -------------------------------- ### Simulate Keyboard Input Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Shows how to type strings, including Unicode characters, and simulate key taps with modifiers. Requires importing 'fmt' and 'robotgo'. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { robotgo.TypeStr("Hello World") // robotgo.TypeStr("だんしゃり") robotgo.TypeStr("だんしゃり") // ustr := uint32(robotgo.CharCodeAt("だんしゃり", 0)) // robotgo.UnicodeType(ustr) robotgo.KeyTap("enter") robotgo.TypeStr("en") robotgo.KeyTap("i", "alt", "command") arr := []string{"alt", "command"} robotgo.KeyTap("i", arr) robotgo.WriteAll("Test") text, err := robotgo.ReadAll() if err == nil { fmt.Println(text) } } ``` -------------------------------- ### Build Binary for Windows (Other to Windows) Source: https://github.com/go-vgo/robotgo/blob/master/docs/install.md Use GOOS, GOARCH, CGO_ENABLED, and specific CC/CXX compilers to build a Windows executable from a non-Windows environment. ```bash GOOS=windows GOARCH=amd64 CGO_ENABLED=1 CC=x86_64-w64-mingw32-gcc CXX=x86_64-w64-mingw32-g++ go build -x ./ ``` -------------------------------- ### Add Keyboard and Mouse Events Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Sets up listeners for keyboard ('k') and left mouse button ('mleft') events. The program will print messages when these events occur. Requires importing 'fmt' and 'robotgo'. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { keve := robotgo.AddEvent("k") if keve { fmt.Println("you press...", "k") } mleft := robotgo.AddEvent("mleft") if mleft { fmt.Println("you press...", "mouse left button") } } ``` -------------------------------- ### Build libei Cgo-free Source: https://github.com/go-vgo/robotgo/blob/master/README.md Builds the libei version for Linux without requiring Cgo or X11 headers. Uses xdg-desktop-portal for GNOME/KDE. ```bash CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags libei ./... ``` -------------------------------- ### Global Event Hook Registration and Handling Source: https://github.com/go-vgo/robotgo/blob/master/README.md Sets up global hooks for keyboard and mouse events. It demonstrates registering specific key combinations (like Ctrl+Shift+Q) to trigger actions and end the hook, as well as basic event listening. ```Go package main import ( "fmt" // "github.com/go-vgo/robotgo" hook "github.com/robotn/gohook" ) func main() { add() low() event() } func add() { fmt.Println("--- Please press ctrl + shift + q to stop hook ---") hook.Register(hook.KeyDown, []string{"q", "ctrl", "shift"}, func(e hook.Event) { fmt.Println("ctrl-shift-q") hook.End() }) fmt.Println("--- Please press w---") hook.Register(hook.KeyDown, []string{"w"}, func(e hook.Event) { fmt.Println("w") }) s := hook.Start() <-hook.Process(s) } func low() { evChan := hook.Start() defer hook.End() for ev := range evChan { fmt.Println("hook: ", ev) } } func event() { ok := hook.AddEvents("q", "ctrl", "shift") if ok { fmt.Println("add events...") } keve := hook.AddEvent("k") if keve { fmt.Println("you press... ", "k") } mleft := hook.AddEvent("mleft") if mleft { fmt.Println("you press... ", "mouse left button") } } ``` -------------------------------- ### Build Wayland Cgo-free Source: https://github.com/go-vgo/robotgo/blob/master/README.md Builds the Wayland version for Linux without requiring Cgo or X11 headers. Requires a wlroots-based compositor. ```bash CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -tags wayland ./... ``` -------------------------------- ### Build Windows Cgo-free Source: https://github.com/go-vgo/robotgo/blob/master/README.md Builds the Windows version of RobotGo without requiring Cgo, GCC, or MinGW. ```bash CGO_ENABLED=0 GOOS=windows GOARCH=amd64 go build -tags win ./... ``` -------------------------------- ### Find and Manipulate Windows with Robotgo Source: https://github.com/go-vgo/robotgo/blob/master/README.md This snippet demonstrates how to find a process ID by name, interact with the window (typing, key presses), activate it, and then kill the process. It also shows how to check if a PID exists and kill it. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { fpid, err := robotgo.FindIds("Google") if err == nil { fmt.Println("pids... ", fpid) if len(fpid) > 0 { robotgo.Type("Hi galaxy!", fpid[0]) robotgo.KeyTap("a", fpid[0], "cmd") robotgo.KeyToggle("a", fpid[0]) robotgo.KeyToggle("a", fpid[0], "up") robotgo.ActivePid(fpid[0]) robotgo.Kill(fpid[0]) } } robotgo.ActiveName("chrome") isExist, err := robotgo.PidExists(100) if err == nil && isExist { fmt.Println("pid exists is", isExist) robotgo.Kill(100) } abool := robotgo.Alert("test", "robotgo") if abool { fmt.Println("ok@@@ ", "ok") } title := robotgo.GetTitle() fmt.Println("title@@@ ", title) } ``` -------------------------------- ### Bitmap Manipulation and Search Source: https://github.com/go-vgo/robotgo/blob/master/README.md Demonstrates capturing a screen region into a bitmap, converting it to an image, and saving it. It also shows how to find and save bitmaps, and locate them within images. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" "github.com/vcaesar/bitmap" ) func main() { bit := robotgo.CaptureScreen(10, 20, 30, 40) // use `defer robotgo.FreeBitmap(bit)` to free the bitmap defer robotgo.FreeBitmap(bit) fmt.Println("bitmap...", bit) img := robotgo.ToImage(bit) // robotgo.SavePng(img, "test_1.png") robotgo.Save(img, "test_1.png") bit2 := robotgo.ToCBitmap(robotgo.ImgToBitmap(img)) fx, fy := bitmap.Find(bit2) fmt.Println("FindBitmap------ ", fx, fy) robotgo.Move(fx, fy) arr := bitmap.FindAll(bit2) fmt.Println("Find all bitmap: ", arr) fx, fy = bitmap.Find(bit) fmt.Println("FindBitmap------ ", fx, fy) bitmap.Save(bit, "test.png") } ``` -------------------------------- ### Cross-Compile Windows64 to Windows32 Source: https://github.com/go-vgo/robotgo/blob/master/docs/install.md Set environment variables for CGO and GOARCH to target a 32-bit Windows executable from a 64-bit environment. ```bash SET CGO_ENABLED=1 SET GOARCH=386 go build main.go ``` -------------------------------- ### Control Mouse Actions Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Demonstrates mouse scrolling, clicking, and smooth movement. Ensure the robotgo library is imported. ```Go package main import ( "github.com/go-vgo/robotgo" ) func main() { // robotgo.ScrollMouse(10, "up") robotgo.Scroll(0, 10) robotgo.MouseClick("left", true) robotgo.MoveSmooth(100, 200, 1.0, 100.0) } ``` -------------------------------- ### Capture and Save Screen Images Source: https://github.com/go-vgo/robotgo/blob/master/README.md Captures the entire screen or specific regions and saves them as PNG or JPEG files. It also demonstrates iterating through multiple displays to capture their content. ```Go package main import ( "fmt" "strconv" "github.com/go-vgo/robotgo" "github.com/vcaesar/imgo" ) func main() { x, y := robotgo.Location() fmt.Println("pos: ", x, y) color := robotgo.GetPixelColor(100, 200) fmt.Println("color---- ", color) sx, sy := robotgo.GetScreenSize() fmt.Println("get screen size: ", sx, sy) bit := robotgo.CaptureScreen(10, 10, 30, 30) defer robotgo.FreeBitmap(bit) img := robotgo.ToImage(bit) imgo.Save("test.png", img) num := robotgo.DisplaysNum() for i := 0; i < num; i++ { robotgo.DisplayID = i img1, _ := robotgo.CaptureImg() path1 := "save_" + strconv.Itoa(i) robotgo.Save(img1, path1+".png") robotgo.SaveJpeg(img1, path1+".jpeg", 50) img2, _ := robotgo.CaptureImg(10, 10, 20, 20) robotgo.Save(img2, "test_"+strconv.Itoa(i)+".png") x, y, w, h := robotgo.GetDisplayBounds(i) img3, err := robotgo.CaptureImg(x, y, w, h) fmt.Println("Capture error: ", err) robotgo.Save(img3, path1+"_1.png") } } ``` -------------------------------- ### Capture and Manipulate Screen Bitmap Source: https://github.com/go-vgo/robotgo/blob/master/examples/README.md Captures a portion of the screen, frees the bitmap resource, finds a bitmap within the screen, and saves a bitmap to a file. Requires importing 'fmt' and 'robotgo'. ```Go package main import ( "fmt" "github.com/go-vgo/robotgo" ) func main() { bitmap := robotgo.CaptureScreen(10, 20, 30, 40) // use `defer robotgo.FreeBitmap(bit)` to free the bitmap defer robotgo.FreeBitmap(bitmap) fmt.Println("...", bitmap) fx, fy := robotgo.FindBitmap(bitmap) fmt.Println("FindBitmap------", fx, fy) robotgo.SaveBitmap(bitmap, "test.png") } ``` -------------------------------- ### Standard Copyright Header for Robotgo Source: https://github.com/go-vgo/robotgo/blob/master/CONTRIBUTING.md Use this standard copyright header for all code contributions to the Robotgo project. Ensure the year range reflects the file's creation and last modification dates. ```go // Copyright (c) 2016-2026 AtomAI, All rights reserved. // // See the COPYRIGHT file at the top-level directory of this distribution and at // https://github.com/go-vgo/robotgo/blob/master/LICENSE // // Licensed under the Apache License, Version 2.0 // // This file may not be copied, modified, or distributed // except according to those terms. ``` -------------------------------- ### Update RobotGo Package Source: https://github.com/go-vgo/robotgo/blob/master/README.md Run this command to update the robotgo package to the latest version. ```bash go get -u github.com/go-vgo/robotgo ``` -------------------------------- ### Robotgo Key Constants Source: https://github.com/go-vgo/robotgo/blob/master/docs/keys.md This snippet lists the string constants used to represent various keys on a keyboard, including alphanumeric keys, function keys, modifier keys, and special keys. These are used when simulating keyboard input with Robotgo. ```Go "A-Z a-z 0-9" "backspace" "delete" "enter" "tab" "esc" "escape" "up" Up arrow key "down" Down arrow key "right" Right arrow key "left" Left arrow key "home" "end" "pageup" "pagedown" "f1" "f2" "f3" "f4" "f5" "f6" "f7" "f8" "f9" "f10" "f11" "f12" "f13" "f14" "f15" "f16" "f17" "f18" "f19" "f20" "f21" "f22" "f23" "f24" "cmd" is the "win" key for windows "cmdl" left command "cmdr" right command // "command" "alt" "altl" left alt "altr" right alt "ctrl" "ctrll" left ctrl "ctrlr" right ctrl "control" "shift" "shiftl" left shift "shiftr" right shift // "right_shift" "capslock" "space" "print" "printscreen" // No Mac support "insert" "menu" Windows only "audio_mute" Mute the volume "audio_vol_down" Lower the volume "audio_vol_up" Increase the volume "audio_play" "audio_stop" "audio_pause" "audio_prev" Previous Track "audio_next" Next Track "audio_rewind" Linux only "audio_forward" Linux only "audio_repeat" Linux only "audio_random" Linux only "num0" "num1" "num2" "num3" "num4" "num5" "num6" "num7" "num8" "num9" "num_lock" "scroll_lock" "pause_break" "num." "num+" "num-" "num*" "num/" "num_clear" "num_enter" "num_equal" // // "numpad_0" No Linux support // "numpad_0" // "numpad_1" // "numpad_2" // "numpad_3" // "numpad_4" // "numpad_5" // "numpad_6" // "numpad_7" // "numpad_8" // "numpad_9" // "numpad_lock" "lights_mon_up" Turn up monitor brightness No Windows support "lights_mon_down" Turn down monitor brightness No Windows support "lights_kbd_toggle" Toggle keyboard backlight on/off No Windows support "lights_kbd_up" Turn up keyboard backlight brightness No Windows support "lights_kbd_down" Turn down keyboard backlight brightness No Windows support ``` -------------------------------- ### Log Keyboard Events with Robotgo Source: https://github.com/go-vgo/robotgo/blob/master/test/index.html Logs keydown and keyup events, capturing the key pressed, its key code, and character code. This requires the Robotgo library to be active. ```javascript window.onkeydown = function(events) { console.log({ event: "keydown", key: events.key, keyCode: events.keyCode, keyChar: events.charCode }); }; ``` ```javascript window.onkeyup = function(events) { console.log({ event: "keyup", key: events.key, keyCode: events.keyCode, keyChar: events.charCode }); }; ``` -------------------------------- ### Log Mouse Click Events with Robotgo Source: https://github.com/go-vgo/robotgo/blob/master/test/index.html Captures and logs click events, including modifier keys like Alt and Shift. Ensure the Robotgo library is initialized before using this. ```javascript window.onclick = function(events) { console.log({ event: "click", altKey: events.altKey, shiftKey: events.shiftKey }); }; ``` -------------------------------- ### OpenCV Image Processing and Template Matching Source: https://github.com/go-vgo/robotgo/blob/master/README.md Utilizes OpenCV (gcv) for image processing tasks like finding images within other images, both by file and by bitmap data. It also demonstrates template matching and SIFT algorithm usage. ```Go package main import ( "fmt" "math/rand" "github.com/go-vgo/robotgo" "github.com/vcaesar/gcv" "github.com/vcaesar/bitmap" ) func main() { opencv() } func opencv() { name := "test.png" name1 := "test_001.png" robotgo.SaveCapture(name1, 10, 10, 30, 30) robotgo.SaveCapture(name) fmt.Print("gcv find image: ") fmt.Println(gcv.FindImgFile(name1, name)) fmt.Println(gcv.FindAllImgFile(name1, name)) bit := bitmap.Open(name1) defer robotgo.FreeBitmap(bit) fmt.Print("find bitmap: ") fmt.Println(bitmap.Find(bit)) // bit0 := robotgo.CaptureScreen() // img := robotgo.ToImage(bit0) // bit1 := robotgo.CaptureScreen(10, 10, 30, 30) // img1 := robotgo.ToImage(bit1) // defer robotgo.FreeBitmapArr(bit0, bit1) img, _ := robotgo.CaptureImg() img1, _ := robotgo.CaptureImg(10, 10, 30, 30) fmt.Print("gcv find image: ") fmt.Println(gcv.FindImg(img1, img)) fmt.Println() res := gcv.FindAllImg(img1, img) fmt.Println(res[0].TopLeft.Y, res[0].Rects.TopLeft.X, res) x, y := res[0].TopLeft.X, res[0].TopLeft.Y robotgo.Move(x, y-rand.Intn(5)) robotgo.MilliSleep(100) robotgo.Click() res = gcv.FindAll(img1, img) // use find template and sift fmt.Println("find all: ", res) res1 := gcv.Find(img1, img) fmt.Println("find: ", res1) img2, _, _ := robotgo.DecodeImg("test_001.png") x, y = gcv.FindX(img2, img) fmt.Println(x, y) } ``` -------------------------------- ### Log Mouse Movement Events with Robotgo Source: https://github.com/go-vgo/robotgo/blob/master/test/index.html Logs mouse movement events, recording the X and Y coordinates of the cursor. This functionality is available when Robotgo is running. ```javascript window.onmousemove = function(events) { console.log({ event: "move", x: events.x, y: events.y }); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.