-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmouse.go
More file actions
74 lines (72 loc) · 1.95 KB
/
mouse.go
File metadata and controls
74 lines (72 loc) · 1.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"fmt"
"time"
// For moving mouse cursor
"github.com/go-vgo/robotgo"
)
// Handles all basic mouse controls.
// movement, drag, left/right click
func mouseCtrl(StateChan chan mpts) {
//var TapCnt int32
var isStart bool
var isMouseDown bool
var TouchX, TouchY int = -1, -1
var TouchTime time.Time
for {
tempState := <-StateChan
if !isLocked {
if tempState.isDown[1] {
isStart, isMouseDown = false, false
TouchX, TouchY = -1, -1
continue
}
if tempState.isDown[0] && !isStart {
isStart = true
TouchTime = time.Now()
//TapCnt = tempState.tapCnt
}
if isStart {
if TouchX != int(touchState.X[0]) {
TouchX = int(touchState.X[0])
}
if TouchY != int(touchState.Y[0]) {
TouchY = int(touchState.Y[0])
}
if TouchX > 0 && TouchY > 0 { //works but wrong, cursor cant be at 0,0
switch touchState.rotation {
case inv:
xval := float32(TouchX) / (float32((maxX + 1)) / float32(resolX))
xinv := halfResolX + (halfResolX - int32(xval))
yval := float32(TouchY) / (float32((maxY + 1)) / float32(resolY))
yinv := halfResolY + (halfResolY - int32(yval))
robotgo.MoveMouse(int(xinv), int(yinv))
case norm:
xval := float32(TouchX) / (float32((maxX + 1)) / float32(resolX))
yval := float32(TouchY) / (float32((maxY + 1)) / float32(resolY))
robotgo.MoveMouse(int(xval), int(yval))
}
if !isMouseDown {
mouse.LeftPress()
fmt.Println("LEFT CLICK DOWN!")
isMouseDown = true
}
}
if !touchState.isDown[0] {
TimeDiff := time.Now().Sub(TouchTime)
if TimeDiff > 600*time.Millisecond && TimeDiff < 2250*time.Millisecond {
mouse.LeftRelease()
fmt.Println("LEFT CLICK UP!")
mouse.RightClick()
fmt.Println("RIGHT CLICK!")
} else {
mouse.LeftRelease()
fmt.Println("LEFT CLICK UP!")
}
isStart, isMouseDown = false, false
TouchX, TouchY = -1, -1
}
}
}
}
}