[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Speed of mouse position capture



On 14 May 2006 at 21:41, Luke Paireepinart wrote:

> Brian Bull wrote:
> >>> I am encountering one difficulty, which is that the speed of mouse 
> >>> position capture seems quite slow. I had expected that the 
> >>>       
[snip]
> >
I am using a very slow Windows computer and can confirm it is not the 
CPU/ram/video card. I have included a very simple freehand drawing 
program stripped from a coloring book program I wrote. It has no 
problem keeping up with the mouse. Pygame 1.7.1 with defaults.

Lenard Lindstrom
<len-l@xxxxxxxxx>

> > Os is XP so presumably not the problem. I think it might be a serial
> > mouse though. Will check. I'm sure I've got a usb mouse sitting about
> > somewhere.
> >
> > Brian
> > "The information contained in this transmission is confidential. It is intended for the named address only. If you are not the named address you may not copy, distribute or take any action in reliance upon this transmission"
> >
> >   
> I wrote a simple "loop through and print out all the mousemotion events" 
> script.
> I even made it to where it only updated a few pixels of the screen 
> rather than the entire thing per iteration.
> I have an optical USB mouse on WinXP and a 1.3ghz AMD 1500+ w/ 512 mb 
> ram and a Geforce FX 5600.
> Granted, my processor's a little on the slow side, but
> it's decently fast for our purposes, I believe.
> Either way, the result of my test is, as yours was, some coordinates 
> being as far as 40 px apart when I moved the mouse very quickly.
> So I'd say none of the following are the issue
> 1) Your mouse format (ps2/serial/usb),   2) your OS,   3) your 
> CPU/ram/video card.
> I'm guessing, like the guy mentioned earlier,
> that SDL just doesn't by default update the mousemotion event fast enough.
> Have you considered just doing a pygame.mouse.get_pos()
> in a separate thread or something of that sort?
> cheers.


import pygame
from pygame.locals import *

cont = True
last_posn = None
dirty_rects = []
screen = pygame.display.set_mode((500, 400))
screen.fill(Color('white'))
pygame.display.flip()
blue = Color('blue')
while cont:
    event = pygame.event.wait()
    while event.type != NOEVENT:
        event_type = event.type
        if event_type == QUIT:
            cont = False
            break
        if event_type == KEYDOWN:
            if event.key == K_q:
                cont = False
                break
        elif event_type == MOUSEBUTTONDOWN:
            last_posn = event.pos
        elif event_type == MOUSEBUTTONUP:
            last_posn = None
        elif event_type == MOUSEMOTION:
            if last_posn is not None:
                dirty_rects.append(pygame.draw.line(screen, blue, last_posn, event.pos, 2))
                last_posn = event.pos
        event = pygame.event.poll()
    if dirty_rects:
        pygame.display.update(dirty_rects)
        dirty_rects = []