Compare commits

..

10 Commits

Author SHA1 Message Date
b20a46cd37 Installation guide
Added installation steps to README file
2024-08-26 15:15:45 +02:00
0984a36f59 Minor improvements
- More general function to click
- Provided functions to press key and write string
- Prevent index error of user choice
2024-07-05 16:14:10 +02:00
b21e09cbb7 Typo 2024-07-05 14:15:35 +02:00
340e193ab6 Moved user interactions to separate goroutine 2023-04-24 15:00:49 +02:00
4d2dbe71e9 Moved helper 2023-04-24 13:52:59 +02:00
0e7d512413 Trying to fix module distribution 2023-04-24 13:40:52 +02:00
916edd704b Moved autoclick.go to root 2023-04-24 13:10:53 +02:00
30f017af72 Capital D 2023-04-24 13:04:52 +02:00
2c12ef6df8 Typo in module name 2023-04-24 13:00:04 +02:00
1b9d849472 Moved autoclick folder 2023-04-24 12:56:48 +02:00
4 changed files with 68 additions and 17 deletions

View File

@@ -1,3 +1,29 @@
# autoclick # autoclick
Go auto-clicker Go auto-clicker that stores groups of locations.
Based on [Robotgo](https://github.com/go-vgo/robotgo).
## Installation
Depending on your OS, you may require
[different dependencies](https://github.com/go-vgo/robotgo?tab=readme-ov-file#requirements).
If you are running MacOS, you just need to install Xcode Command Line Tools
and grant Go the accessibility permissions when prompted from the system.
```sh
xcode-select --install
```
Finally, once dependencies are met, to install autoclick run:
```bash
go install gogs.davte.it/Davte/autoclick@latest
```
To launch autoclick from any path, add this to your bash profile or bashrc:
```bash
export PATH="$PATH:/$HOME/go/bin"
```

9
autoclick.go Normal file
View File

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

View File

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

View File

@@ -1,4 +1,4 @@
package autoclick package helper
import ( import (
"fmt" "fmt"
@@ -22,9 +22,17 @@ 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() { 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.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 { func (p1 *Point) GetDistance(p2 *Point) float64 {
@@ -145,7 +153,16 @@ func StringOscillator(s string, amplitude int) chan string {
return c return c
} }
func ClickRepeteadly(s *SavedGroups) { 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 { 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)
} }
@@ -159,6 +176,9 @@ func ClickRepeteadly(s *SavedGroups) {
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,6 +208,7 @@ func ClickRepeteadly(s *SavedGroups) {
} }
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
} }
} }
@@ -203,15 +224,19 @@ 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)
addSavedGroup(s) go interactWithUser(s, yamlFile, c)
storeSavedGroups(s, yamlFile)
go ClickRepeteadly(s)
if <-quit == 1 { if <-quit == 1 {
fmt.Println("Exiting...") fmt.Println("Exiting...")
} else { } else {