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

Re: [pygame] newbie: events and timing



On Tue, Apr 15, 2003 at 07:08:41PM +0200, Christoph Lehmann wrote:
> I have some python code, where I wait in a loop for a trigger signal on
> the lpt port.
> during this waiting-loop: can I receive any mouse button events? are
> they logged with some time-stamps, so that I can get, after I left my
> waiting loop, the info, which mouse button has been pressed, and also at
> what time.

Yes you can. You just have to make sure that in your polling loop you
keep the pygame event handling up. This can f.ex. be done by calling
pygame.event.pump().
If you need to know at what time the button was pressed you'd might want
to actually take a closer look at the events you get to find out if
there's a mouse event involved. There are a couple of ways to do this.
Check the pygame.org site for some examples (chimp tutorial etc) of how
to do this.
Here's a simple untested snippet that might or might not work for you:

buttons = []

while polling_ltp():
    for event in pygame.event.get():
        if event.type == MOUSEBUTTONDOWN:
            buttons.append((event.button, event.pos, pygame.time.get_ticks()))

Should give you a list of tuples with information about the button, the mouse
position where the button was pressed and the time (measured in ticks since
pygame.init here) when that event happened.

-- 
Raiser, Frank aka CrashChaos
IRC: irc.openprojects.net #pygame

"The most exciting phrase to hear in science, the one that heralds new
discoveries, is not 'Eureka!' ('I found it!') but rather 'hmm....that's
funny...'"
  -- Isaac Asimov