mirror of
https://github.com/prashantgupta24/automatic-mouse-mover.git
synced 2024-12-22 16:34:11 +00:00
Merge pull request #2 from prashantgupta24/dev
incorporating new activity tracker changes
This commit is contained in:
commit
c857b54b00
19
cmd/main.go
19
cmd/main.go
@ -5,7 +5,7 @@ import (
|
|||||||
|
|
||||||
"github.com/getlantern/systray"
|
"github.com/getlantern/systray"
|
||||||
"github.com/getlantern/systray/example/icon"
|
"github.com/getlantern/systray/example/icon"
|
||||||
"github.com/prashantgupta24/automatic-mouse-mover/src/mousemover"
|
"github.com/prashantgupta24/automatic-mouse-mover/pkg/mousemover"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
@ -17,29 +17,26 @@ func onReady() {
|
|||||||
systray.SetIcon(icon.Data)
|
systray.SetIcon(icon.Data)
|
||||||
systray.SetTitle("AMM")
|
systray.SetTitle("AMM")
|
||||||
ammStart := systray.AddMenuItem("Start", "start the app")
|
ammStart := systray.AddMenuItem("Start", "start the app")
|
||||||
ammPause := systray.AddMenuItem("Pause", "pause the app")
|
ammStop := systray.AddMenuItem("Stop", "stop the app")
|
||||||
systray.AddSeparator()
|
systray.AddSeparator()
|
||||||
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
mQuit := systray.AddMenuItem("Quit", "Quit the whole app")
|
||||||
// Sets the icon of a menu item. Only available on Mac.
|
// Sets the icon of a menu item. Only available on Mac.
|
||||||
//mQuit.SetIcon(icon.Data)
|
//mQuit.SetIcon(icon.Data)
|
||||||
var quit chan struct{}
|
mouseMover := mousemover.GetInstance()
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ammStart.ClickedCh:
|
case <-ammStart.ClickedCh:
|
||||||
fmt.Println("starting the app")
|
fmt.Println("starting the app")
|
||||||
quit = mousemover.Start()
|
mouseMover.Start()
|
||||||
//notify.SendMessage("starting the app")
|
//notify.SendMessage("starting the app")
|
||||||
|
|
||||||
case <-ammPause.ClickedCh:
|
case <-ammStop.ClickedCh:
|
||||||
fmt.Println("pausing the app")
|
fmt.Println("stopping the app")
|
||||||
if quit != nil {
|
mouseMover.Quit()
|
||||||
quit <- struct{}{}
|
|
||||||
} else {
|
|
||||||
fmt.Println("app is not started")
|
|
||||||
}
|
|
||||||
|
|
||||||
case <-mQuit.ClickedCh:
|
case <-mQuit.ClickedCh:
|
||||||
fmt.Println("Requesting quit")
|
fmt.Println("Requesting quit")
|
||||||
|
mouseMover.Quit()
|
||||||
systray.Quit()
|
systray.Quit()
|
||||||
fmt.Println("Finished quitting")
|
fmt.Println("Finished quitting")
|
||||||
return
|
return
|
||||||
|
27
glide.lock
generated
27
glide.lock
generated
@ -1,5 +1,5 @@
|
|||||||
hash: 0e9d554853b2c3ed23ba323715540d961c06465a1a125959a698d6162e17f91d
|
hash: 0e9d554853b2c3ed23ba323715540d961c06465a1a125959a698d6162e17f91d
|
||||||
updated: 2019-03-13T16:48:18.629713-07:00
|
updated: 2019-03-22T15:34:56.64781-07:00
|
||||||
imports:
|
imports:
|
||||||
- name: github.com/BurntSushi/xgb
|
- name: github.com/BurntSushi/xgb
|
||||||
version: 27f122750802c950b2c869a5b63dafcf590ced95
|
version: 27f122750802c950b2c869a5b63dafcf590ced95
|
||||||
@ -41,21 +41,28 @@ imports:
|
|||||||
version: 193b4935d4b146c729d763c2c59a0d3e7f3cee8a
|
version: 193b4935d4b146c729d763c2c59a0d3e7f3cee8a
|
||||||
subpackages:
|
subpackages:
|
||||||
- clipboard
|
- clipboard
|
||||||
|
- name: github.com/konsorten/go-windows-terminal-sequences
|
||||||
|
version: f55edac94c9bbba5d6182a4be46d86a2c9b5b50e
|
||||||
- name: github.com/lxn/win
|
- name: github.com/lxn/win
|
||||||
version: 0040366d745006bbf7528ac96de2de375846aa79
|
version: 0040366d745006bbf7528ac96de2de375846aa79
|
||||||
- name: github.com/otiai10/gosseract
|
- name: github.com/otiai10/gosseract
|
||||||
version: ca64adaa320dc563d0966d58d3811512cb3362dc
|
version: d442e510d0b37ec1f332a61a04e323ecee91d0cb
|
||||||
- name: github.com/oxtoacart/bpool
|
- name: github.com/oxtoacart/bpool
|
||||||
version: 8c4636f812cc8920c26e2002b988c878b1fd6f5e
|
version: 8c4636f812cc8920c26e2002b988c878b1fd6f5e
|
||||||
- name: github.com/prashantgupta24/activity-tracker
|
- name: github.com/prashantgupta24/activity-tracker
|
||||||
version: d567f73735304c333bba0a151cf4aca8602c1ae2
|
version: d60ddb4a3211e471b1a3fcd9b5dec960a453c79c
|
||||||
subpackages:
|
subpackages:
|
||||||
|
- internal/pkg/logging
|
||||||
|
- internal/pkg/mouse
|
||||||
|
- internal/pkg/service
|
||||||
|
- pkg/activity
|
||||||
|
- pkg/tracker
|
||||||
- src/activity
|
- src/activity
|
||||||
- src/mouse
|
- src/mouse
|
||||||
- name: github.com/robotn/gohook
|
- name: github.com/robotn/gohook
|
||||||
version: bbbbefb5ff8541a05870596ea081ad8581b5879f
|
version: a7a38946710e764b00839160e13a92b09e40e96a
|
||||||
- name: github.com/shirou/gopsutil
|
- name: github.com/shirou/gopsutil
|
||||||
version: ebc97eefea9b062f9f1624c042c98f196fc90248
|
version: 381f7cc0bf4ccb60157fd5c6eaabfdfc681e6c2f
|
||||||
subpackages:
|
subpackages:
|
||||||
- cpu
|
- cpu
|
||||||
- host
|
- host
|
||||||
@ -65,16 +72,22 @@ imports:
|
|||||||
- process
|
- process
|
||||||
- name: github.com/shirou/w32
|
- name: github.com/shirou/w32
|
||||||
version: bb4de0191aa41b5507caa14b0650cdbddcd9280b
|
version: bb4de0191aa41b5507caa14b0650cdbddcd9280b
|
||||||
|
- name: github.com/sirupsen/logrus
|
||||||
|
version: dae0fa8d5b0c810a8ab733fbd5510c7cae84eca4
|
||||||
- name: github.com/StackExchange/wmi
|
- name: github.com/StackExchange/wmi
|
||||||
version: e0a55b97c70558c92ce14085e41b35a894e93d3d
|
version: e0a55b97c70558c92ce14085e41b35a894e93d3d
|
||||||
- name: github.com/vcaesar/imgo
|
- name: github.com/vcaesar/imgo
|
||||||
version: 13af122cf2fa6117048933e141c0b52f19116ca6
|
version: 13af122cf2fa6117048933e141c0b52f19116ca6
|
||||||
|
- name: golang.org/x/crypto
|
||||||
|
version: b7391e95e576cacdcdd422573063bc057239113d
|
||||||
|
subpackages:
|
||||||
|
- ssh/terminal
|
||||||
- name: golang.org/x/image
|
- name: golang.org/x/image
|
||||||
version: 0694c2d4d067f97ebef574d63a763ee8ab559da7
|
version: 3fc05d484e9f77dd51816890e05f2602e4ca4d65
|
||||||
subpackages:
|
subpackages:
|
||||||
- bmp
|
- bmp
|
||||||
- name: golang.org/x/sys
|
- name: golang.org/x/sys
|
||||||
version: fead79001313d15903fb4605b4a1b781532cd93e
|
version: f49334f85ddcf0f08d7fb6dd7363e9e6d6b777eb
|
||||||
subpackages:
|
subpackages:
|
||||||
- unix
|
- unix
|
||||||
- windows
|
- windows
|
||||||
|
109
pkg/mousemover/misc.go
Normal file
109
pkg/mousemover/misc.go
Normal file
@ -0,0 +1,109 @@
|
|||||||
|
package mousemover
|
||||||
|
|
||||||
|
// 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")
|
||||||
|
// // // }
|
||||||
|
// // }
|
||||||
|
|
||||||
|
// }
|
86
pkg/mousemover/mouseMover.go
Normal file
86
pkg/mousemover/mouseMover.go
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
package mousemover
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"log"
|
||||||
|
"time"
|
||||||
|
|
||||||
|
"github.com/go-vgo/robotgo"
|
||||||
|
"github.com/prashantgupta24/activity-tracker/pkg/tracker"
|
||||||
|
)
|
||||||
|
|
||||||
|
var instance *mouseMover
|
||||||
|
|
||||||
|
type mouseMover struct {
|
||||||
|
quit chan struct{}
|
||||||
|
isRunning bool
|
||||||
|
}
|
||||||
|
|
||||||
|
const (
|
||||||
|
timeout = 100 //ms
|
||||||
|
)
|
||||||
|
|
||||||
|
func (m *mouseMover) Start() {
|
||||||
|
m.quit = make(chan struct{})
|
||||||
|
|
||||||
|
frequency := 5 //value always in seconds
|
||||||
|
activityTracker := &tracker.Instance{
|
||||||
|
Frequency: frequency,
|
||||||
|
//LogLevel: "debug", //if we want verbose logging
|
||||||
|
}
|
||||||
|
|
||||||
|
heartbeatCh := activityTracker.Start()
|
||||||
|
|
||||||
|
go func(m *mouseMover) {
|
||||||
|
m.isRunning = true
|
||||||
|
movePixel := 10
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case heartbeat := <-heartbeatCh:
|
||||||
|
if !heartbeat.IsActivity {
|
||||||
|
commCh := make(chan bool)
|
||||||
|
go moveMouse(movePixel, commCh)
|
||||||
|
select {
|
||||||
|
case wasMouseMoveSuccess := <-commCh:
|
||||||
|
if wasMouseMoveSuccess {
|
||||||
|
fmt.Printf("\nmoving mouse at : %v\n\n", time.Now())
|
||||||
|
movePixel *= -1
|
||||||
|
}
|
||||||
|
case <-time.After(timeout * time.Millisecond):
|
||||||
|
//timeout, do nothing
|
||||||
|
log.Printf("timeout happened after %vms while trying to move mouse", timeout)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
case <-m.quit:
|
||||||
|
fmt.Println("stopping mouse mover")
|
||||||
|
m.isRunning = false
|
||||||
|
activityTracker.Quit()
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}(m)
|
||||||
|
}
|
||||||
|
|
||||||
|
func moveMouse(movePixel int, commCh chan bool) {
|
||||||
|
currentX, currentY := robotgo.GetMousePos()
|
||||||
|
moveToX := currentX + movePixel
|
||||||
|
moveToY := currentY + movePixel
|
||||||
|
robotgo.MoveMouse(moveToX, moveToY)
|
||||||
|
commCh <- true
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *mouseMover) Quit() {
|
||||||
|
//making it idempotent
|
||||||
|
if m != nil && m.isRunning {
|
||||||
|
m.quit <- struct{}{}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//GetInstance gets the singleton instance for mouse mover app
|
||||||
|
func GetInstance() *mouseMover {
|
||||||
|
if instance == nil {
|
||||||
|
instance = &mouseMover{}
|
||||||
|
}
|
||||||
|
return instance
|
||||||
|
}
|
@ -1,109 +0,0 @@
|
|||||||
package mousemover
|
|
||||||
|
|
||||||
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")
|
|
||||||
// // }
|
|
||||||
// }
|
|
||||||
|
|
||||||
}
|
|
@ -1,44 +0,0 @@
|
|||||||
package mousemover
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/go-vgo/robotgo"
|
|
||||||
"github.com/prashantgupta24/activity-tracker/src/activity"
|
|
||||||
"github.com/prashantgupta24/activity-tracker/src/mouse"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Start() (quit chan struct{}) {
|
|
||||||
quit = make(chan struct{})
|
|
||||||
|
|
||||||
activityTracker := &activity.ActivityTracker{
|
|
||||||
TimeToCheck: 15,
|
|
||||||
}
|
|
||||||
|
|
||||||
heartbeatCh, quitActivityTracker := activityTracker.Start()
|
|
||||||
|
|
||||||
go func() {
|
|
||||||
movePixel := 10
|
|
||||||
for {
|
|
||||||
select {
|
|
||||||
case heartbeat := <-heartbeatCh:
|
|
||||||
if !heartbeat.IsActivity {
|
|
||||||
currentMousePos := mouse.GetPosition()
|
|
||||||
fmt.Println("moving mouse at : ", time.Now())
|
|
||||||
nextMouseMov := &mouse.Position{
|
|
||||||
MouseX: currentMousePos.MouseX + movePixel,
|
|
||||||
MouseY: currentMousePos.MouseY + movePixel,
|
|
||||||
}
|
|
||||||
robotgo.MoveMouse(nextMouseMov.MouseX, nextMouseMov.MouseY)
|
|
||||||
movePixel *= -1
|
|
||||||
}
|
|
||||||
case <-quit:
|
|
||||||
fmt.Println("stopping mouse mover")
|
|
||||||
quitActivityTracker <- struct{}{}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}()
|
|
||||||
return quit
|
|
||||||
}
|
|
Loading…
Reference in New Issue
Block a user