Compare commits

..

No commits in common. "603b4e87efff50b7c266d52c29c6f8115b1b8fc3" and "026f522a8982c2979240abcc429f786928d321b8" have entirely different histories.

3 changed files with 18 additions and 66 deletions

View File

@ -1,9 +0,0 @@
package main
import (
"gogs.davte.it/Davte/autoclick/helper"
)
func main() {
helper.RunAutoClicker()
}

9
cmd/main/main.go Normal file
View File

@ -0,0 +1,9 @@
package main
import (
"gogs.davte.it/davte/autoclick"
)
func main() {
autoclick.RunAutoClicker()
}

View File

@ -1,4 +1,4 @@
package helper package autoclick
import ( import (
"fmt" "fmt"
@ -6,7 +6,6 @@ import (
"math" "math"
"os" "os"
"os/signal" "os/signal"
"strconv"
"strings" "strings"
"time" "time"
@ -23,17 +22,9 @@ func (p Point) String() string {
return fmt.Sprintf("(%v, %v)", p.X, p.Y) return fmt.Sprintf("(%v, %v)", p.X, p.Y)
} }
func (p Point) Click(button ...string) { func (p Point) Click() {
buttonToClick := "left"
if len(button) > 0 && (button[0] == "left" || button[0] == "right") {
buttonToClick = button[0]
}
robotgo.Move(p.X, p.Y) robotgo.Move(p.X, p.Y)
robotgo.Click(buttonToClick, false) robotgo.Click("left", false)
}
func (p Point) RightClick() {
p.Click("right")
} }
func (p1 *Point) GetDistance(p2 *Point) float64 { func (p1 *Point) GetDistance(p2 *Point) float64 {
@ -154,16 +145,7 @@ func StringOscillator(s string, amplitude int) chan string {
return c return c
} }
func press(key string) { func ClickRepeteadly(s *SavedGroups) {
robotgo.KeyTap(key)
}
func keyboardWrite(s string) {
robotgo.TypeStr(s)
robotgo.MilliSleep(100)
}
func ClickRepeatedly(s *SavedGroups, c chan os.Signal) {
for index, g := range s.Groups { for index, g := range s.Groups {
fmt.Printf("- Press %v to select %v\n", index+1, g.Name) fmt.Printf("- Press %v to select %v\n", index+1, g.Name)
} }
@ -177,9 +159,6 @@ func ClickRepeatedly(s *SavedGroups, c chan os.Signal) {
fmt.Scanln(&discard) fmt.Scanln(&discard)
continue continue
} }
if choice > len(s.Groups) {
choice = 0
}
} }
selection := s.Groups[choice-1] selection := s.Groups[choice-1]
fmt.Printf("You selected %v. I'll be clicking in the following positions:\n", selection.Name) fmt.Printf("You selected %v. I'll be clicking in the following positions:\n", selection.Name)
@ -188,32 +167,10 @@ func ClickRepeatedly(s *SavedGroups, c chan os.Signal) {
} }
o := StringOscillator(".", 15) o := StringOscillator(".", 15)
var t int var t int
n := 1
var minDistance float64 var minDistance float64
for { for {
for i, p := range selection.Points { for _, p := range selection.Points {
if selection.Name == "akoya" { // hardcoded for Akoya presentation. #TODO: better handling (selection action list)
if i == 0 {
p.RightClick()
time.Sleep(100 * time.Millisecond)
press("v")
time.Sleep(500 * time.Millisecond)
} else if i == 1 {
time.Sleep(200 * time.Millisecond)
p.Click() p.Click()
time.Sleep(200 * time.Millisecond)
keyboardWrite(strconv.Itoa(n))
n++
time.Sleep(100 * time.Millisecond)
press("enter")
time.Sleep(500 * time.Millisecond)
} else {
p.Click()
time.Sleep(100 * time.Millisecond)
}
} else {
p.Click()
}
time.Sleep(100 * time.Millisecond) time.Sleep(100 * time.Millisecond)
} }
fmt.Println(<-o) fmt.Println(<-o)
@ -231,7 +188,6 @@ func ClickRepeatedly(s *SavedGroups, c chan os.Signal) {
} }
if t >= 10 { if t >= 10 {
fmt.Println("You stayed away too long, exiting...") fmt.Println("You stayed away too long, exiting...")
c <- os.Interrupt
return return
} }
} }
@ -247,19 +203,15 @@ func cleanUp(c chan os.Signal) chan int {
return r return r
} }
func interactWithUser(s *SavedGroups, yamlFile string, c chan os.Signal) {
addSavedGroup(s)
storeSavedGroups(s, yamlFile)
ClickRepeatedly(s, c)
}
func RunAutoClicker() { func RunAutoClicker() {
c := make(chan os.Signal, 1) c := make(chan os.Signal, 1)
quit := cleanUp(c) quit := cleanUp(c)
signal.Notify(c, os.Interrupt) signal.Notify(c, os.Interrupt)
yamlFile := "SavedGroups.yaml" yamlFile := "SavedGroups.yaml"
s := getSavedGroups(yamlFile) s := getSavedGroups(yamlFile)
go interactWithUser(s, yamlFile, c) addSavedGroup(s)
storeSavedGroups(s, yamlFile)
go ClickRepeteadly(s)
if <-quit == 1 { if <-quit == 1 {
fmt.Println("Exiting...") fmt.Println("Exiting...")
} else { } else {