-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_control.py
111 lines (98 loc) · 3.13 KB
/
simple_control.py
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
import keyboard, time
import pyautogui
__version__ = "0.0.1"
#just type a letter that is given
def click_button(button: str, length: float) -> None:
keyboard.press(button)
time.sleep(length/2)
keyboard.release(button)
time.sleep(length/2)
#move the mouse relative to it's starting point
def move_mouse(x: int, y: int, length: float) -> None:
pyautogui.move(x,y,length)
def move_mouse_to(x: int, y: int, length: float, mode: int=0) -> None:
'''
modes:
0 - using move_mouse()
1 - randomised move_mouse() #indev
2 - teleport mouse to location
'''
if mode == 0:
current_position = get_mouse_position()
target = x - current_position[0], y - current_position[1]
move_mouse(target[0], target[1], length)
elif mode == 1:
pass
elif mode == 2:
pass
else:
pass
#type using click_button
def typing(text: str, length: float, raw:bool = False) -> None:
#if raw just write whatever we are given
#else, we preprocess the text before typing
if raw:
dt = length/len(text)
for i in text:
click_button(button = i,
length = dt)
else:
typing_auto_preprocess(text = text,
length = length)
def mouse_press(left: bool = True) -> None:
#click left or right mouse button
key = 'LEFT'
if left == False:
key = 'RIGHT'
pos = get_mouse_position()
pyautogui.click(x = pos[0],
y = pos[1],
button = key)
def mouse_hold(left: bool, length: float) -> None:
#hold left or right mouse button
ellipsis
def mouse_drag(left: bool, length: float) -> None:
#hold left or right mouse button and move the mouse
ellipsis
def get_mouse_position() -> [int, int]:
#return current mouse position
pos = pyautogui.position()
return [pos[0], pos[1]]
def get_keys_pressed():
return keyboard.read_key()
def is_key_pressed(key) -> bool:
return keyboard.is_pressed(key)
def test1():
time.sleep(1)
click_button('a', 0.02)
move_mouse(100, 100, 0.2)
print(get_mouse_position())
time.sleep(1)
print(get_keys_pressed())
print(is_key_pressed('a'))
def test2():
move_mouse_to(100, 100, 1)
#delay between clicks in seconds
def double_click(left:bool = True, delay:float = 0.05):
mouse_press(left = left)
time.sleep(delay)
mouse_press(left = left)
def typing_auto_preprocess(text: str, length: float):
dt = length / len(text)
for char in text:
if char == ' ':
#chars.append('space')
click_button(button = 'space',
length = dt)
#check if capital
elif char == char.upper():
click_button(button =f'shift+{char.lower()}',
length = dt)
elif char == '':
pass
else:
click_button(button = char,
length = dt)
def test3():
time.sleep(2)
typing_auto_preprocess('NeVer GoNNa Give you Up', 2)