Original go implementation of cross-platform AutoIt and Key wizard function sample code

Source: Internet
Author: User
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 bounds, will be completed 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/robotgo


The following part of the code to organize the test, will be in the future version of the improvement, and attach comments (please see the code to run, the impact of the operation is responsible):

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 ()//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 coordinates 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 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}


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.