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

[pygame] Re: loss of rapidly repeated keypresses (from a barcode gun keyboard)



On Wed, Dec 2, 2009 at 9:40 AM, Bob the Hamster <Bob@xxxxxxxxxxxxxxxxxxx> wrote:
> I am writing a pygame application that uses a USB barcode gun which
> behaves as a keyboard. (AFAIK most barcode scanners behave as
> keyboards)
>
> When you scan a barcode, it rapidly types the text it reads from the barcode.
>
> My application is listening for this keyboard input as pygame events,
> and appending them to a string. This *mostly* works great.
>
> The problem I am having is with input that has a lot of repeated
> characters, such as "9999999" If such a barcode is the FIRST one I
> scan, I usally only get "9" or "99" instead of the whole string. If I
> have scanned other things, then I *usually* get the whole "9999999".
>
> I am guessing that somehow pygame is throwing away key input events
> because they are coming too fast and look like duplicates.
>
> Has anybody else experienced a problem like this? Does anybody have
> any ideas for workarounds or further avenues of testing?
>
> I should note that when I use this same barcode scanner to scan the
> same repetitious barcodes into a terminal, or a text editor, or a word
> processor, I NEVER lose characters, so I am pretty sure this is not a
> hardware issue with the scanner itself.

Some more info on this problem.

1) I was able us a c++ test program to verify that this is a problem
with SDL's event system, and not a pygame-specific problem.

2) I discovered the pygame.fastevent module, and my readonf of its
documentation suggested to me that it was intended to fix exactly this
sort of problem. It does not. it suffers from exactly the same event
loss. (Darn it, I thought I was on to something there! The fact that
pygame.fastevent is apparently not any faster than pygame.event would
have been nicely explained if fastevent had been able to handle events
that "come too fast" for the regular event module... oh, well.)

3) Reading the SDL Mailing list, I learned that event loss when the
event queue is full is already a topic of discussion for SDL1.3

4) I also discovered, while searching for a workaround, an SDL mailing
list post from Sam Lantinga last January mentioning a "simple callback
mechanism for SDL events that bypasses the event queue". Does anybody
know if there is a pygame way to make event callbacks?

---
James Paige