-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscreen-spots.py
150 lines (118 loc) · 4.35 KB
/
screen-spots.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
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
from talon import ctrl, Module, actions, storage, imgui, ui, canvas, settings
from talon.skia import Paint
mod = Module()
mod.setting(
"screen_spots_heatmap_color",
type=str,
default="ff0F9D58",
desc="set the color of the drawn dots in the spot heatmap",
)
mod.setting(
"screen_spots_heatmap_size",
type=int,
default=5,
desc="set the size of the drawn dots in the spot heatmap",
)
mod.setting(
"screen_spots_slow_move_enabled",
type=int,
default=0,
desc="slows the mouse's movement speed during spot commands when enabled (some games don't detect the instant mouse movement correctly). Set to 0 (the default) to disable, any other number to enable",
)
# Initialize with the spots in storage if there are any. All keys should be strings
spot_dictionary = storage.get("screen-spots", {})
heatmap_showing = False
@imgui.open(y=0)
def gui_list_keys(gui: imgui.GUI):
global spot_dictionary
gui.text("spot names")
gui.line()
for key in spot_dictionary:
gui.text(key)
gui.spacer()
if gui.button("Spot close"):
actions.user.close_spot_list()
def backup_spot():
"""Save the spot dictionary to be used again upon reload"""
storage.set("screen-spots", spot_dictionary)
can = canvas.Canvas.from_screen(ui.main_screen())
def draw_spot(canvas):
canvas.paint.color = settings.get('user.screen_spots_heatmap_color')
canvas.paint.style = Paint.Style.FILL
for key, spot in spot_dictionary.items():
canvas.draw_circle(spot[0], spot[1], settings.get('user.screen_spots_heatmap_size'))
can.register('draw', draw_spot)
can.hide()
def refresh():
if heatmap_showing:
can.freeze()
@mod.action_class
class SpotClass:
def save_spot(spot_key: str):
"""Saves the current mouse position (to a specific key phrase)"""
x = actions.mouse_x()
y = actions.mouse_y()
spot_dictionary[spot_key] = [x, y]
refresh()
backup_spot()
def toggle_spot_heatmap():
"""Display the spot on the screen"""
global can, heatmap_showing
if heatmap_showing:
can.hide()
heatmap_showing = False
else:
can.freeze()
heatmap_showing = True
def move_to_spot(spot_key: str) -> bool:
"""
Moves the cursor to a location, if one was saved for the given key.
Returns true if the cursor was moved
"""
if spot_key in spot_dictionary:
spot = spot_dictionary[spot_key]
if settings.get('user.screen_spots_slow_move_enabled'):
actions.user.slow_mouse_move(spot[0], spot[1])
else:
actions.mouse_move(spot[0], spot[1])
return True
return False
def click_spot(spot_key: str):
"""Clicks the saved mouse position (if it exists) then returns your cursor to its current position"""
current_x = actions.mouse_x()
current_y = actions.mouse_y()
was_moved = actions.user.move_to_spot(spot_key)
if was_moved:
if settings.get('user.screen_spots_slow_move_enabled'):
actions.user.slow_mouse_click()
actions.user.slow_mouse_move(current_x, current_y)
else:
ctrl.mouse_click(button=0, hold=16000)
actions.mouse_move(current_x, current_y)
def drag_spot(spot_key: str, release_drag: int=0):
"""Drag the mouse from its current location to the saved position (if it exists)"""
if spot_key in spot_dictionary:
actions.user.mouse_drag(0)
actions.user.move_to_spot(spot_key)
if release_drag != 0:
actions.sleep("50ms")
actions.mouse_release(0)
def clear_spot_dictionary():
"""Reset the active spot list to a new empty dictionary"""
global spot_dictionary
spot_dictionary = {}
backup_spot()
refresh()
def clear_spot(spot_key: str):
"""Remove a specific saved spot"""
global spot_dictionary
if spot_key in spot_dictionary:
del spot_dictionary[spot_key]
backup_spot()
refresh()
def list_spot():
"""Display a list of existing spot names"""
gui_list_keys.show()
def close_spot_list():
"""Closes the list of existing spot names"""
gui_list_keys.hide()