2023-05-17 10:16:15 +00:00
|
|
|
import base
|
|
|
|
|
from pynput import mouse
|
|
|
|
|
|
|
|
|
|
class MouseEvents():
|
|
|
|
|
def __init__(self):
|
|
|
|
|
listener = mouse.Listener(
|
|
|
|
|
on_move=on_move,
|
|
|
|
|
on_click=on_click,
|
|
|
|
|
on_scroll=on_scroll)
|
|
|
|
|
listener.start()
|
2023-10-30 19:43:35 +00:00
|
|
|
|
2023-05-17 10:16:15 +00:00
|
|
|
# MOUSE EVENTS/LISTENER
|
|
|
|
|
def on_move(x, y):
|
|
|
|
|
if base.data["move"]:
|
2023-10-30 19:43:35 +00:00
|
|
|
print("MOVING")
|
|
|
|
|
|
2023-05-17 10:16:15 +00:00
|
|
|
if base.data["mouse_distance_x"] == 0:
|
|
|
|
|
base.data["mouse_distance_x"] = base.sights.get(base.data["active_sight"]).pos().x()-x
|
|
|
|
|
if base.data["mouse_distance_y"] == 0:
|
|
|
|
|
base.data["mouse_distance_y"] = base.sights.get(base.data["active_sight"]).pos().y()-y
|
|
|
|
|
|
|
|
|
|
x_point = x+base.data["mouse_distance_x"]
|
|
|
|
|
y_point = y+base.data["mouse_distance_y"]
|
2023-10-30 19:43:35 +00:00
|
|
|
|
|
|
|
|
print( str(x_point) + " x " + str(y_point))
|
2023-05-17 10:16:15 +00:00
|
|
|
base.sights.get(base.data["active_sight"]).move(x_point, y_point)
|
|
|
|
|
|
|
|
|
|
def on_click(x, y, button, pressed):
|
|
|
|
|
if pressed:
|
|
|
|
|
print("pressed on " +base.data["active_sight"])
|
|
|
|
|
else:
|
|
|
|
|
print("released")
|
|
|
|
|
base.data["mouse_distance_x"] = 0
|
|
|
|
|
base.data["mouse_distance_y"] = 0
|
|
|
|
|
base.data["move"] = False
|
|
|
|
|
|
|
|
|
|
def on_scroll(x, y, dx, dy):
|
|
|
|
|
print('Scrolled {0} at {1}'.format(
|
|
|
|
|
'down' if dy < 0 else 'up',
|
2023-10-30 19:43:35 +00:00
|
|
|
(x, y)))
|
|
|
|
|
|