diff --git a/helper/helper.go b/helper/helper.go index 8de19cf..bcab813 100644 --- a/helper/helper.go +++ b/helper/helper.go @@ -6,6 +6,7 @@ import ( "math" "os" "os/signal" + "strconv" "strings" "time" @@ -22,9 +23,17 @@ func (p Point) String() string { return fmt.Sprintf("(%v, %v)", p.X, p.Y) } -func (p Point) Click() { +func (p Point) Click(button ...string) { + buttonToClick := "left" + if len(button) > 0 && (button[0] == "left" || button[0] == "right") { + buttonToClick = button[0] + } robotgo.Move(p.X, p.Y) - robotgo.Click("left", false) + robotgo.Click(buttonToClick, false) +} + +func (p Point) RightClick() { + p.Click("right") } func (p1 *Point) GetDistance(p2 *Point) float64 { @@ -145,6 +154,15 @@ func StringOscillator(s string, amplitude int) chan string { return c } +func press(key string) { + 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 { fmt.Printf("- Press %v to select %v\n", index+1, g.Name) @@ -159,6 +177,9 @@ func ClickRepeatedly(s *SavedGroups, c chan os.Signal) { fmt.Scanln(&discard) continue } + if choice > len(s.Groups) { + choice = 0 + } } selection := s.Groups[choice-1] fmt.Printf("You selected %v. I'll be clicking in the following positions:\n", selection.Name) @@ -167,9 +188,21 @@ func ClickRepeatedly(s *SavedGroups, c chan os.Signal) { } o := StringOscillator(".", 15) var t int + n := 1 var minDistance float64 for { for _, p := range selection.Points { + if selection.Name == "akoya" { // hardcoded for Akoya presentation. #TODO: better handling (selection action list) + p.RightClick() + time.Sleep(100 * time.Millisecond) + press("v") + time.Sleep(50 * time.Millisecond) + keyboardWrite(strconv.Itoa(n)) + n++ + time.Sleep(50 * time.Millisecond) + press("enter") + time.Sleep(2000 * time.Millisecond) + } p.Click() time.Sleep(100 * time.Millisecond) }