Update example

This commit is contained in:
vCaesar 2017-03-24 23:31:17 +08:00
parent 8553f75c77
commit a030081a06
2 changed files with 32 additions and 18 deletions

View File

@ -21,8 +21,9 @@ func main() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Control the keyboard // Control the keyboard
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
robotgo.TypeString("Hello World") // importing "Hello World" robotgo.TypeString("Hello World") // Importing "Hello World"
robotgo.KeyTap("enter") // Press "enter"
robotgo.KeyTap("enter") // Press "enter"
robotgo.KeyTap("a", "control") robotgo.KeyTap("a", "control")
robotgo.KeyTap("h", "command") // Hide window robotgo.KeyTap("h", "command") // Hide window
@ -35,23 +36,29 @@ func main() {
robotgo.KeyTap("m", "command") // minimize window robotgo.KeyTap("m", "command") // minimize window
robotgo.KeyTap("f1", "control") robotgo.KeyTap("f1", "control")
robotgo.KeyTap("a", "control") robotgo.KeyTap("a", "control")
robotgo.KeyToggle("a", "down") robotgo.KeyToggle("a", "down")
robotgo.KeyToggle("a", "down", "alt") robotgo.KeyToggle("a", "down", "alt")
robotgo.KeyToggle("a", "down", "alt", "command") robotgo.KeyToggle("a", "down", "alt", "command")
robotgo.KeyToggle("enter", "down") robotgo.KeyToggle("enter", "down")
robotgo.TypeString("en") robotgo.TypeString("en")
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Control the mouse // Control the mouse
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
robotgo.MoveMouse(100, 200) // Move the mouse to 100, 200 robotgo.MoveMouse(100, 200) // Move the mouse to 100, 200
robotgo.MouseClick() // Click the left mouse button
robotgo.MouseClick("right", false) // Click the right mouse button robotgo.MouseClick() // Click the left mouse button
robotgo.MouseClick("left", true) // double click the left mouse button robotgo.MouseClick("right", false) // Click the right mouse button
robotgo.MouseClick("left", true) // double click the left mouse button
robotgo.ScrollMouse(10, "up") // Scrolls the mouse either up robotgo.ScrollMouse(10, "up") // Scrolls the mouse either up
robotgo.MouseToggle("down", "right") // Toggles right mouse button robotgo.MouseToggle("down", "right") // Toggles right mouse button
robotgo.MoveMouseSmooth(100, 200) // Smooth move the mouse to 100, 200
robotgo.MoveMouseSmooth(100, 200) // Smooth move the mouse to 100, 200
robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0) robotgo.MoveMouseSmooth(100, 200, 1.0, 100.0)
x, y := robotgo.GetMousePos() // Gets the mouse coordinates x, y := robotgo.GetMousePos() // Gets the mouse coordinates
fmt.Println("pos:", x, y) fmt.Println("pos:", x, y)
if x == 456 && y == 586 { if x == 456 && y == 586 {
@ -89,6 +96,7 @@ func main() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Bitmap // Bitmap
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Gets all of the screen // Gets all of the screen
abitMap := robotgo.CaptureScreen() abitMap := robotgo.CaptureScreen()
fmt.Println("abitMap...", abitMap) fmt.Println("abitMap...", abitMap)
@ -123,34 +131,34 @@ func main() {
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// Global event listener // Global event listener
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
fmt.Println("---please press v---") fmt.Println("--- Please press v---")
eve := robotgo.AddEvent("v") eve := robotgo.AddEvent("v")
if eve == 0 { if eve == 0 {
fmt.Println("---you press v---", "v") fmt.Println("--- You press v---", "v")
} }
fmt.Println("---please press k---") fmt.Println("--- Please press k---")
keve := robotgo.AddEvent("k") keve := robotgo.AddEvent("k")
if keve == 0 { if keve == 0 {
fmt.Println("---you press k---", "k") fmt.Println("--- You press k---", "k")
} }
fmt.Println("---please press f1---") fmt.Println("--- Please press f1---")
feve := robotgo.AddEvent("f1") feve := robotgo.AddEvent("f1")
if feve == 0 { if feve == 0 {
fmt.Println("you press...", "f1") fmt.Println("You press...", "f1")
} }
fmt.Println("---please press left mouse button---") fmt.Println("--- Please press left mouse button---")
mleft := robotgo.AddEvent("mleft") mleft := robotgo.AddEvent("mleft")
if mleft == 0 { if mleft == 0 {
fmt.Println("---you press left mouse button---", "mleft") fmt.Println("--- You press left mouse button---", "mleft")
} }
mright := robotgo.AddEvent("mright") mright := robotgo.AddEvent("mright")
if mright == 0 { if mright == 0 {
fmt.Println("---you press right mouse button---", "mright") fmt.Println("--- You press right mouse button---", "mright")
} }
// Stop AddEvent // Stop AddEvent
@ -164,15 +172,21 @@ func main() {
fmt.Println("ok@@@", "ok") fmt.Println("ok@@@", "ok")
} }
robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel") robotgo.ShowAlert("hello", "robotgo", "Ok", "Cancel")
pid := robotgo.GetPID() // Get the current process id pid := robotgo.GetPID() // Get the current process id
fmt.Println("pid----", pid) fmt.Println("pid----", pid)
mdata := robotgo.GetActive() // Get current Window Active mdata := robotgo.GetActive() // Get current Window Active
hwnd := robotgo.GetHandle() // Get current Window Handle
hwnd := robotgo.GetHandle() // Get current Window Handle
fmt.Println("hwnd---", hwnd) fmt.Println("hwnd---", hwnd)
bhwnd := robotgo.GetBHandle() // Get current Window Handle bhwnd := robotgo.GetBHandle() // Get current Window Handle
fmt.Println("bhwnd---", bhwnd) fmt.Println("bhwnd---", bhwnd)
title := robotgo.GetTitle() // Get current Window title title := robotgo.GetTitle() // Get current Window title
fmt.Println("title-----", title) fmt.Println("title-----", title)
robotgo.CloseWindow() // close current Window robotgo.CloseWindow() // close current Window
robotgo.SetActive(mdata) // set Window Active robotgo.SetActive(mdata) // set Window Active
} }

View File

@ -52,7 +52,7 @@ import (
) )
const ( const (
version string = "v0.43.0.289, Matterhorn Alps!" version string = "v0.43.0.295, Matterhorn Alps!"
) )
// GetVersion get version // GetVersion get version