Tracking the movement of the mouse, not the pointer

I have a code that tracks the movement of the mouse pointer and, depending on the X coordinate, rotates the green pixel relative to a certain radius. The problem is that I can't increase the size of the X coordinate because the program will be closely linked to another one.

Tell me how to accurately read the mouse movement, getting the vector of mouse movement, and not the coordinates of the pointer, which has a limited area of movement on the screen, unlike the mouse. I want to get the vector of mouse movement regardless of whether the mouse pointer is pointing at any side of the screen or not. Teleporting the mouse to the other side of the screen if one side is reached is not the solution to my problem.

All the libraries I've reviewed that help track the movement of the mouse actually provide only cursor tracking functionality, not the mouse itself. Or I just haven't found a solution in these libraries.

I am attaching my dirty code:

import win32api
import win32gui
import math
import pyautogui
import keyboard 
import pyttsx3

def circle_coordinates(x, y, r, ug):
    angle_rad = math.radians(ug)
    x_coord = x + r * math.cos(angle_rad)
    y_coord = y + r * math.sin(angle_rad)
    yield x_coord, y_coord

def main():
    step = 9
    radius = 121
    duration = 40
    freq = 540
    s = 18
    engine = pyttsx3.init()
    engine.setProperty('rate',2000)

    shift_pressed = False 
    alt_pressed = False 
    dc = win32gui.GetDC(0)
    wt = win32api.RGB(0, 255, 0)

    center_x, center_y = 960, 540
    pyautogui.FAILSAFE = False

    while True:
        try:
            ugx, ugy = pyautogui.position()
            if ugx == 1919:
                ugx = 1
                pyautogui.moveTo(1, ugy)
            if ugx == 0:
                ugx = 1918
                pyautogui.moveTo(1918, ugy)
            ugx = ugx * 360 / 1919
            with open('file.txt', 'r') as f:
                s = int(f.readline())
      
            for x, y in circle_coordinates(center_x, center_y, radius * (s / 100), ugx):
                if keyboard.is_pressed('shift') and not shift_pressed and radius < 700: 
                    radius += step 
                    shift_pressed = True
                elif not keyboard.is_pressed('shift'): 
                    shift_pressed = False 
      
                if keyboard.is_pressed('alt') and not alt_pressed and radius > 121: 
                    radius -= step                     
                    alt_pressed = True
                elif not keyboard.is_pressed('alt'): 
                    alt_pressed = False 
                win32gui.SetPixel(dc, int(x), int(y), wt)

        except Exception as ex:
            print(ex)
       
if __name__ == '__main__':
    main()`

I have looked at various libraries for tracking mouse movements, but have not found a solution.

Upvotes: 0

Views: 22

Answers (0)

Related Questions