Skip to content

Instantly share code, notes, and snippets.

@sekcompsci
Last active August 5, 2018 16:21
Show Gist options
  • Save sekcompsci/4bf8e17af54fe8f6052175766ec59c92 to your computer and use it in GitHub Desktop.
Save sekcompsci/4bf8e17af54fe8f6052175766ec59c92 to your computer and use it in GitHub Desktop.
autoclick basic way with golang (robotgo)
package main
import (
"fmt"
"time"
"github.com/go-vgo/robotgo"
)
func main() {
fmt.Println("Auto Click Start!")
x, y := getPosition()
delay := setTimeInterval()
for {
fmt.Println("Move to:", x, y, "and clickLeft", true)
robotgo.MoveClick(x, y, "left", true)
fmt.Println("delay:", delay)
time.Sleep(delay)
}
}
func getPosition() (int, int) {
fmt.Println("Click position do you want.")
mleft := robotgo.AddEvent("mleft")
if mleft == 0 {
x, y := robotgo.GetMousePos()
fmt.Println("you click position:", x, y)
return x, y
}
return 0, 0
}
func setTimeInterval() (time.Duration) {
var timeInterval uint
fmt.Print("input timeinterval for click (second): ")
fmt.Scanf("%d", &timeInterval)
fmt.Println("you set time:", timeInterval, "s")
// convert number to duration
duration := time.Duration(timeInterval) * time.Second
return duration
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment