1
votes

Here is my code, very simple:

import pygame

def run_game():

    pygame.init()

    screen = pygame.display.set_mode((1200,800))

    while True:

        screen.fill((55,55,55))

        for event in pygame.event.get():
            if event.type == pygame.MOUSEBUTTONDOWN:
                print(pygame.mouse.get_pos())

            elif event.type == pygame.MOUSEMOTION:
                print(pygame.mouse.get_pos())


        pygame.display.flip()


run_game()

When I click on one position, it shows the (x,y) coordinate. When I click on position one, it shows (x1,y1), then SOMETIMES after I change my mouse to position 2, and click on it, it still shows (x1,y1) instead of the correct coordinate. When this happens, if I don't move my mouse and keep click on position 2, it will keep showing (x1,y1) until I change mouse to somewhere else. Can someone explains to me why is that happened? Thanks.

1
btw I'm using mouse touchpad on macbook, if that matters. - Wenchang Li
even if I comment out the whole MOUSEMOTION elif statement it still not working. so it has nothing to do with the MOUSEMOTION statement. - Wenchang Li
BTW: for different events you have different values in event - for MOUSEBUTTONDOWN and MOUSEMOTION you have position in event.pos - see more in yellow table on pygame.org/docs/ref/event.html - furas
After trying both on my pc and mac, the problem is Macbook itself not handling mouse event detection well. The same program works perfectly on pc with a mouse. But even when I connect my mouse to Mac it still not working properly, so that problem is not the touchpad but some settings on Mac. - Wenchang Li

1 Answers

1
votes

You can add a print statement before mouse motion and mouse down so that you can easily differentiate between both.