pygame-ce icon indicating copy to clipboard operation
pygame-ce copied to clipboard

Delay after mouse click when using pygame.mouse.get_pos() on macOS

Open makorendev opened this issue 2 years ago • 4 comments
trafficstars

Environment:

  • Operating system: macOS Ventura 13.4.1
  • Python version: 3.11.4
  • SDL version: 2.26.4
  • PyGame version: 2.3.0
  • Relevant hardware: Wireless mouse connected through Bluetooth. Doesn't seem to happen when using the built-in trackpad.

Current behavior:

When moving the mouse and clicking at the same time, the value returned from pygame.mouse.get_pos seems to pause for about 10 frames before updating normally again.

Expected behavior:

This function should return an accurate result every frame.

Screenshots

image

Steps to reproduce:

  1. Copy the code below into a blank script and run.
  2. Move the mouse around while clicking the left mouse button.
  3. Observe the circle pausing for a few frames after each click.

Test code

import pygame
pygame.init()
screen = pygame.display.set_mode((500, 500))

clock = pygame.time.Clock()

running = True
while running:
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            running = False
    
    clock.tick(60)
    
    pos = pygame.mouse.get_pos()

    screen.fill("black")
    pygame.draw.circle(screen, "red", pos, 25)
    print(pos)

    pygame.display.flip()

The issue persists with or without clock.tick.

makorendev avatar Jul 01 '23 06:07 makorendev

Hello, thanks for the bug report. Can you test with another mouse, to eliminate any hardware issues? If that's not the fault, then maybe test with other applications to tell whether it's an os/driver issue?

I just tested with your code on my Ubuntu machine, I did not see anything wrong visually and there was no pausing, but maybe I'm not understanding your issue exactly

ankith26 avatar Jul 06 '23 16:07 ankith26

I've tested with a separate wired mouse and I get the same issue. No other applications give me this issue, but I don't know if any of my other applications use SDL.

makorendev avatar Jul 06 '23 19:07 makorendev

Can't reproduce this on Windows with my Bluetooth mouse. I suspect this might be some kind of USB hardware issue.

MyreMylar avatar Nov 01 '23 21:11 MyreMylar

Hello, I was looking through old issues just to see what was up and I was able to replicate this. M1 mac on MacOS sonoma. See attached video for it happening. To create this clip I bound right option to left click, and then moved around quickly on my touch pad. I did this because its very hard to click while moving correctly on a touch pad. I also slightly modified the code to show exactly when it is clicked.

(You might have to download the video to go frame by frame)

https://github.com/pygame-community/pygame-ce/assets/77908661/08840d14-9cc9-4b42-9be0-799b94aab694

Things of note, the position of the system mouse on screen freezes for a couple frames, then it moves and 1 frame later pygame detects the click. Then it takes 2 more frames for the position to update again.

The OS cursor freezing makes me maybe think its a MacOS issue, but I don't have any testing to support this and it seems unlikely. Probably its just the way MacOS handles touch pad input, I think for further testing the mouse should be moved by a program instead of a user to eliminate that sort of error. Might do it later

Kn4ughty avatar Apr 04 '24 03:04 Kn4ughty