I've been trying to handle mouse support using pygame, and I've found that 
clicks are being missed outright.  I've tested my code thoroughly* and the 
problem is on the pygame end.  I have included the relevant code below.  Thank 
you in advance.

* - To be clear here, I've tried everything I can think of with no effect.  
This includes disabling all code other than the key check in gameLoop(), and 
also disabling the call to 'handleInputEvent()' so that only the print 
statements remain.  I still miss click events, with the print sometimes giving 
me two presses before a release or vice versa.  I only click the left mouse 
button, so it's not a false positive, and I've checked the length of the event 
queue and never seen it rise past single digits (sometimes 2-3 due to mouse 
motion and other events).  Framerates are fairly constant (+/- 1 FPS @ ~60FPS 
total), and Key events print a normal press/release pattern just fine.  The 
mouse issue resulted in bad code functionality, so this is a serious issue for 
adding mouse support.

def gameLoop():
    done = False
    while not done:
        #... snip
        res = checkKeysGUI()    # check what keys are pressed, HW-level
        #... snip
    return 0

def checkKeysGUI():
    ''' check the SDL Event Queue '''
    for event in pygame.event.get():
        if event.type == SYSWMEVENT:
            pass
       
        elif event.type == QUIT:      # Quit Button, the big red X
            handleAppQuit()
           
        elif(event.type == MOUSEMOTION):
            ''' check the mouse buttons; TODO: do we need to act if mouse 
enters/leaves window?'''
            updateMouse(event.pos[0], event.pos[1]) # [0] = X, [1] = Y
   
        elif(event.type == MOUSEBUTTONUP or event.type == MOUSEBUTTONDOWN):
            ''' we actually have a mouse click, dispatch it to handlers'''
            pressed = (event.type == MOUSEBUTTONDOWN)
            ''' **DEBUG ONLY** '''
            if(pressed):
                print('keypress')
            else:
                print('keyrelease')
            if not (handleInputEvent(kdef5.MOUSEMAP[event.button], pressed)):
                return False
           
        elif(event.type == KEYUP or event.type == KEYDOWN):
            ''' check the keyboard keys vs. our keymap '''
            pressed = (event.type == KEYDOWN)
            ''' **DEBUG ONLY** '''
            if(pressed):
                print('keypress')
            else:
                print('keyrelease')
            if not (handleInputEvent(kdef5.KEYMAP[event.key], pressed)):
                return False

        return True

Reply via email to