Minor improvements

- More general function to click
- Provided functions to press key and write string
- Prevent index error of user choice
This commit is contained in:
Davte 2024-07-05 16:14:10 +02:00
parent b21e09cbb7
commit 0984a36f59
Signed by: Davte
GPG Key ID: 70336F92E6814706

View File

@ -22,9 +22,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 +153,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 +176,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)