I need to be able to track the mouse and display it on a pygame window even though the mouse is confined in a location such as 200, 200. My code is this
import pygame
import time
from pygame.locals import *
import pyautogui
pygame.init()
DISPLAY=pygame.display.set_mode((int(2560/3),int(1440/3)),0,32)
WHITE=(255,255,255)
BLUE=(0,0,255)
DISPLAY.fill(WHITE)
w = pyautogui.position()
x_mouse = w.x
y_mouse = w.y
oldx = x_mouse
oldy = y_mouse
div = 3
x = x_mouse/div
y = y_mouse/div
while True:
DISPLAY.fill(WHITE)
pygame.draw.rect(DISPLAY,BLUE,(x,y,50,50))
w = pyautogui.position()
x_mouse = w.x
y_mouse = w.y
if x_mouse > oldx:
x+=(x_mouse-oldx)/div
if x_mouse < oldx:
x-=(oldx-x_mouse)/div
if y_mouse > oldy:
y+=(y_mouse-oldy)/div
if y_mouse < oldy:
y-=(oldy-y_mouse)/div
oldx = x_mouse
oldy = y_mouse
for event in pygame.event.get():
if event.type==QUIT:
pygame.quit()
pygame.display.update()
This works fine but it completely breaks when the mouse is confined in a location, any way to get around this issue?