-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmouse.c
171 lines (168 loc) · 3.28 KB
/
mouse.c
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
#include <stdio.h>
#include <stdlib.h>
#define WINVER 0x0500
#include <windows.h>
#include "mouse.h"
/*
* Created by Tyler Gillam in Fall 2018 as a side project
* Code needs to be refactored to be more readable as well as refactoring all of the if-elses
* Free to use and modify
*/
//TODO: Refactor code into multiple methods and files to improve readability and modularity
//moves mouse to position x,y using a human like algorithm
void moveMouse(int x, int y){
int a = 0;
int b = 0;
int mouseTimes = rand()%10;
for(int i = 0; i<mouseTimes; i++){
int speed = rand()%3+3;
POINT cursor;
GetCursorPos(&cursor);
int startX = cursor.x;
int startY = cursor.y;
int xDiff = 0;
int yDiff = 0;
int xRand = 0;
int yRand = 0;
if(x>cursor.x){
xDiff = (x-cursor.x)*.5;
}
else{
xDiff = (cursor.x - x)*.5;
}
if(y>cursor.y){
yDiff = (y-cursor.y)*.5;
}
else{
yDiff = (cursor.y - y)*.5;
}
if(xDiff != 0){
xRand = rand()%xDiff;
}
else{
xRand = 0;
}
if(yDiff != 0){
yRand = rand()%yDiff;
}
else{
yRand = 0;
}
if(x>startX && y>startY){
randomizeMouse(startX+xRand, startY+yRand, speed);
}
else if(x>startX && y<startY){
if((startY - yRand) <= 0){
b = 0;
}
else{
b = (startY - yRand);
}
randomizeMouse(startX+xRand, b, speed);
}
else if(x<startX &&y>startY){
if((startX - xRand) <= 0){
a = 0;
}
else{
a = (startX - xRand);
}
randomizeMouse(a, startY+yRand, speed);
}
else if(x<startX &&y<startY){
if((startY - yRand) <= 0){
b = 0;
}
else{
b = (startY - yRand);
}
randomizeMouse(startX-xRand, b, speed);
}
else{
if((startY - yRand) <= 0){
b = 0;
}
else{
b = (startY - yRand);
}
randomizeMouse(startX-xRand, b, speed);
}
}
int speed = rand()%3+3;
randomizeMouse(x, y, speed);
}
//moves mouse in a predictable motion to x,y with a specific speed
void randomizeMouse(int x, int y, int speed){
POINT p;
GetCursorPos(&p);
int z = 0;
int b = 0;
int xDiff = 0;
int yDiff = 0;
int newRand = 0;
while(p.x!=x || p.y!=y){
if(p.x>x){
xDiff = p.x - x;
}
else{
xDiff = x-p.x;
}
if(p.y>y){
yDiff = p.y - y;
}
else{
yDiff = y - p.y;
}
newRand = rand()%2+4;
z = rand()%newRand;
b = rand()%speed;
if(xDiff>yDiff){
if(z!=0){
if(p.x != x){
if(p.x < x){
SetCursorPos(p.x+1, p.y);
}
else{
SetCursorPos(p.x-1, p.y);
}
}
}
else{
if(p.y != y){
if(p.y < y){
SetCursorPos(p.x, p.y+1);
}
else{
SetCursorPos(p.x, p.y-1);
}
}
}
}
else{
if(z==0){
if(p.x != x){
if(p.x < x){
SetCursorPos(p.x+1, p.y);
}
else{
SetCursorPos(p.x-1, p.y);
}
}
}
else{
if(p.y != y){
if(p.y < y){
SetCursorPos(p.x, p.y+1);
}
else{
SetCursorPos(p.x, p.y-1);
}
}
}
}
if(b == 1){
Sleep(1);
}
GetCursorPos(&p);
}
}