This is a creation in Article, where the information may have evolved or changed.
Robotgo v0.40.0 the mouse keyboard operation has been greatly improved, due to cross-platform switching test trouble (merging several platform code to compare the upload code is wasted a lot of time) and C code production efficiency and go and JavaScript is not a level, There is no support window and process corresponding window selection and window bounds, will be perfect in the next version, the keyboard operation may be some input method on some problems, please switch to the system input method (the current priority to complete the window handle problem, the problem will be resolved later).
Project Address: Https://github.com/go-vgo/rob ...
The following is the code of the local test section, will be completed in the future version, and attach comments (please see the code to run):
Package Mainimport (. "FMT" "Github.com/go-vgo/robotgo") func main () {//keyboard control Robotgo. Typestring ("Hello World")//Enter Hello World Robotgo. Keytap ("enter")//press the ENTER key Robotgo. Keytap ("A", "control") Robotgo. Keytap ("H", "command")//Hide window Robotgo. Keytap ("I", "alt", "command")//Press "I", "alt", "command" key combination arr: = []string{"alt", "command"} robotgo. Keytap ("I", arr)//Press "I", "alt", "command" key combination Robotgo. Keytap ("w", "command")//Close window Robotgo. Keytap ("M", "command")//Minimized window Robotgo. Keytap ("F1", "control") Robotgo. Keytap ("A", "control") Robotgo. Keytoggle ("A", "down")//Toggle a key Robotgo. Keytoggle ("A", "Down", "Alt") Robotgo. Keytoggle ("A", "Down", "alt", "command") Robotgo. Keytoggle ("Enter", "Down") Robotgo. Typestring ("en")//mouse control Robotgo. Movemouse (100, 200)//move the mouse to 100, 200 position Robotgo. MouseClick ()//left mouse button click Robotgo. MouseClick ("right", false)//Robotgo. MouseClick ("left", true)//double-click Robotgo. Scrollmouse ("Up")//scroll up the mouse RoboTgo. Mousetoggle ("Down", "right")//mouse-button toggle Robotgo. Movemousesmooth (100, 200)//smooth mobile mouse to the Robotgo. Movemousesmooth (100, 200, 1.0, 100.0)//Set smooth movement speed X, y: = Robotgo. Getmousepos ()//get mouse coordinate position Println ("POS:", x, y) if x = = 456 && y = = 586 {Println ("mouse ...", "586") } robotgo. Mousetoggle ("Up") Robotgo. Movemouse (x, y) Robotgo. Movemouse (+) for I: = 0; I < 1080; i + = + + Println (i) Robotgo. Movemouse (+, I)}//Screen control//robotgo. Capturescreen ()//Bit_map: = Robotgo. Capturescreen ()//Println ("Capturescreen ...", bit_map)//gbit_map: = Robotgo. Capture_screen () Gbit_map: = Robotgo. Bcapturescreen ()//Get screen bitmap Println ("Capture_screen ...", Gbit_map. Width) SX, sy: = Robotgo. Getscreensize ()//Get screen width and height Println ("...", SX, sy) Color: = Robotgo. Getpixelcolor (100, 200)//Gets the coordinates 100, 200 of the color Println ("color----", color, "-----------------") Color2: = Robotgo. Getpixelcolor (10, 20)//Get coordinate 10, 20 color PriNTLN ("Color---", color2)//Bitmap Abit_map: = Robotgo. Capturescreen ()//Get full screen bitmap Println ("A ...", abit_map) Bit_map: = Robotgo. Capturescreen (100, 200, 30, 40)//Get 100, 200, 30, 40 bitmap Println ("Capturescreen ...", bit_map)//Println ("...", bi T_map. Width, Bit_map. Bytesperpixel) FX, FY: = Robotgo. Findbitmap (BIT_MAP)//Find bitmap Println ("findbitmap------", FX, FY) Bit_pos: = Robotgo. Getportion (Bit_map, 10, 10, 11, 10)//Intercept bitmap Println (bit_pos) Bit_str: = Robotgo. Tostringbitmap (Bit_map)//tostring bitmap Println ("Bit_str ...", bit_str)//Sbit_map: = Robotgo. Bitmapfromstring (BIT_STR, 2)//Println ("...", Sbit_map) Robotgo. Savebitmap (Bit_map, "test.png")//Save bitmap for picture Robotgo. Savebitmap (Bit_map, "Test31.tif", 1) Robotgo. Convert ("Test.png", "test.tif")//conversion bitmap picture format open_bit: = Robotgo. Openbitmap ("test.tif")//Open picture bitmap Println ("Open ...", open_bit)//Global Listener Event PRINTLN ("---press v key---") Eve: = Robotgo. Addevent ("V") if Eve = = 0 {Println ("---you press the V key---", "V"} Println ("---press the K key---") keve: = Robotgo. Addevent ("K") if Keve = = 0 {Println ("---you press K key---", "K")} Println ("---Press the left mouse button---") mleft: = Robotgo. Addevent ("Mleft") if Mleft = = 0 {Println ("---you press left button---", "mleft")}//Mright: = Robotgo. Addevent ("Mright")//if Mright = = 0 {//PRINTLN ("---you press right button---", "mright")//}//Robotgo. Lstop ()//window Abool: = Robotgo. Showalert ("Hello", "Robotgo")//pop-up window if Abool = = 0 {Println ("ok@@@", "Confirm")} Robotgo. Showalert ("Hello", "Robotgo", "Confirm", "Cancel")//Robotgo. Getpid () Mdata: = Robotgo. Getactive ()//Gets the current window hwnd: = Robotgo. GetHandle ()//Gets the current window HWND Println ("HWND---", hwnd) Title: = Robotgo. GetTitle ()//Gets the current window title Println ("title-----", title) Robotgo. CloseWindow ()//Close the current window Robotgo. SetActive (mdata)//setactive window}