[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [pygame] key press question



On Tue, 2001-12-11 at 08:53, Robert Flemming wrote:
> So I'm working on my first application and I've got a question.  I was
> looking at the newbie guide about the different ways of handling keyboard
> events and I've got a bit of a problem.
> 
> Initially I had written my application to use the event queue since I wanted
> to make sure and not miss any key presses.  As things progressed I needed to
> be able to use "chording".  Since my main loop was pretty dull I decided to
> try and switch things over to use state checking.  The problem I found is that
> I'm getting repeating characters.  I tinkered with the set_repeat value, but
> that only seems to work when using the event queue.  Am I missing something
> obvious here or is that just the way things works?
> 
> Like I said originally I'd prefer to use the event queue, but I'm not sure how
> to go about handling the simultaneous key presses.  I looked at several of the
> projects hoping to find an example, but came up empty.  Any thoughts or samples
> to point me in the right direction (for either option) are appreciated.
> Thanks Much

set_repeat only controls how often KEYDOWN events are put in the event
queue. If you check the key state twice while the keys are down, you're
going to see that the keys are down twice. It seems to me that it would
be fairly straightforward to check for two KEYDOWN events prior to a
KEYUP event to look for chording. You just need to have a time threshold
similar to doubleclicks or chorded mouse button presses; if you get two
KEYDOWN events within a given time period and no KEYUP event, that's a
chord. Make sure if you're not checking events that you're at least
calling pygame.event.pump(). 

PGP signature