mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2024-12-22 16:34:11 +00:00
initial commit
This commit is contained in:
commit
3daf896c84
109
misc.go
Normal file
109
misc.go
Normal file
@ -0,0 +1,109 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
// func isPointerIdle(comm chan bool) {
|
||||
// for {
|
||||
// x1, y1 := robotgo.GetMousePos()
|
||||
// time.Sleep(time.Second * 3)
|
||||
// x2, y2 := robotgo.GetMousePos()
|
||||
|
||||
// if x1 == x2 && y1 == y2 {
|
||||
// fmt.Println("idle")
|
||||
// //comm <- true
|
||||
// } else {
|
||||
// fmt.Println("moving")
|
||||
// comm <- false
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
func checkIfMouseMoved(x1, y1, x2, y2 int, comm chan bool) {
|
||||
if x1 == x2 && y1 == y2 {
|
||||
fmt.Println("idle")
|
||||
//return false
|
||||
//comm <- true
|
||||
} else {
|
||||
fmt.Println("moving")
|
||||
comm <- false
|
||||
//return true
|
||||
}
|
||||
}
|
||||
|
||||
func isMouseClick(comm chan bool) {
|
||||
|
||||
}
|
||||
|
||||
func moveMouse(comm chan bool) {
|
||||
ticker := time.NewTicker(time.Second * 3)
|
||||
val := true
|
||||
movePixel := 10
|
||||
x1, y1 := robotgo.GetMousePos()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
fmt.Println("ticked")
|
||||
x2, y2 := robotgo.GetMousePos()
|
||||
checkIfMouseMoved(x1, y1, x2, y2, comm)
|
||||
if val {
|
||||
fmt.Println("moving mouse because idle")
|
||||
//x1, y1 := robotgo.GetMousePos()
|
||||
robotgo.Move(x2+movePixel, y2+movePixel)
|
||||
movePixel *= -1
|
||||
} else {
|
||||
val = true
|
||||
}
|
||||
x1 = x2
|
||||
y1 = y2
|
||||
case val = <-comm:
|
||||
fmt.Println("val received: ", val)
|
||||
}
|
||||
}
|
||||
}
|
||||
func main() {
|
||||
// log.SetOutput(os.Stdout)
|
||||
// log.Println("starting")
|
||||
// log.Println("logging")
|
||||
// //robotgo.ScrollMouse(100, "up")
|
||||
// robotgo.Move(100, 100)
|
||||
// x, y := robotgo.GetMousePos()
|
||||
// fmt.Println("pos: ", x, y)
|
||||
|
||||
comm := make(chan bool)
|
||||
moveMouse(comm)
|
||||
//isPointerIdle(comm)
|
||||
|
||||
// for {
|
||||
// // wheelDown := robotgo.AddEvent("wheelDown")
|
||||
// // wheelRight := robotgo.AddEvent("wheelRight")
|
||||
|
||||
// // fmt.Println("wheelDown : ", wheelDown)
|
||||
// // fmt.Println("wheelRight : ", wheelRight)
|
||||
// count := 0
|
||||
// go func(count *int) {
|
||||
// for {
|
||||
// mleft := robotgo.AddEvent("mleft")
|
||||
// if mleft == 0 {
|
||||
// *count++
|
||||
// fmt.Println("mleft : ", *count)
|
||||
// time.Sleep(time.Millisecond * 500)
|
||||
// }
|
||||
// }
|
||||
|
||||
// }(&count)
|
||||
|
||||
// mright := robotgo.AddEvent("mright")
|
||||
|
||||
// fmt.Println("mright : ", mright)
|
||||
|
||||
// // if mleft {
|
||||
// // fmt.Println("you press... ", "mouse left button")
|
||||
// // }
|
||||
// }
|
||||
|
||||
}
|
87
src/mouseMover.go
Normal file
87
src/mouseMover.go
Normal file
@ -0,0 +1,87 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/go-vgo/robotgo"
|
||||
)
|
||||
|
||||
const (
|
||||
timeToCheck = 3
|
||||
)
|
||||
|
||||
type mousePos struct {
|
||||
mouseX int
|
||||
mouseY int
|
||||
}
|
||||
|
||||
func moveMouse(comm chan struct{}, quit chan struct{}) {
|
||||
ticker := time.NewTicker(time.Second * timeToCheck)
|
||||
isIdle := true
|
||||
movePixel := 10
|
||||
lastMousePos := getMousePos()
|
||||
for {
|
||||
select {
|
||||
case <-ticker.C:
|
||||
fmt.Println("ticked : ", isIdle)
|
||||
currentMousePos := getMousePos()
|
||||
if isIdle && isPointerIdle(currentMousePos, lastMousePos) {
|
||||
fmt.Println("moving mouse")
|
||||
nextMouseMov := &mousePos{
|
||||
mouseX: currentMousePos.mouseX + movePixel,
|
||||
mouseY: currentMousePos.mouseY + movePixel,
|
||||
}
|
||||
robotgo.Move(nextMouseMov.mouseX, nextMouseMov.mouseY)
|
||||
lastMousePos = nextMouseMov
|
||||
} else {
|
||||
lastMousePos = currentMousePos
|
||||
}
|
||||
isIdle = true
|
||||
movePixel *= -1
|
||||
case <-comm:
|
||||
isIdle = false
|
||||
fmt.Println("val received: ", isIdle)
|
||||
case <-quit:
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func isPointerIdle(currentMousePos, lastMousePos *mousePos) bool {
|
||||
fmt.Println("current : ", currentMousePos)
|
||||
fmt.Println("last : ", lastMousePos)
|
||||
|
||||
if currentMousePos.mouseX == lastMousePos.mouseX &&
|
||||
currentMousePos.mouseY == lastMousePos.mouseY {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func getMousePos() *mousePos {
|
||||
x, y := robotgo.GetMousePos()
|
||||
return &mousePos{
|
||||
mouseX: x,
|
||||
mouseY: y,
|
||||
}
|
||||
}
|
||||
|
||||
func isMouseClicked(comm chan struct{}) {
|
||||
go func() {
|
||||
for {
|
||||
mleft := robotgo.AddEvent("mleft")
|
||||
if mleft == 0 {
|
||||
//fmt.Println("mleft clicked")
|
||||
comm <- struct{}{}
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func main() {
|
||||
comm := make(chan struct{})
|
||||
quit := make(chan struct{})
|
||||
go isMouseClicked(comm)
|
||||
moveMouse(comm, quit)
|
||||
}
|
Loading…
Reference in New Issue
Block a user