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

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



On Thu, Dec 03, 2009 at 12:12:14AM -0600, Jake b wrote:
>    Have you tried changing .key.set_repeat(something_small) ?

I tried that, but it made no difference.

>    And how are you polling for the events?

Here is my test code:


#!/usr/bin/env python

import pygame
from pygame.locals import *

pygame.init()
screen = pygame.display.set_mode((640, 480))
font = pygame.font.Font(None, 24)
clock = pygame.time.Clock()

text = ""

def say(s, ypos, col=(255,255,255)):
  img = font.render(s, True, col)
  screen.blit(img, (0, ypos))
  if img.get_rect().width > screen.get_rect().width:
    return True # overflowed the screen width
  return False

while True:
  clock.tick(60)
  for event in pygame.event.get():
    if event.type == pygame.QUIT:
      raise SystemExit
    if event.type == pygame.KEYDOWN:
      if event.key == K_ESCAPE:
        raise SystemExit
      text += event.unicode
  screen.fill((0,0,0))
  say("If first input comes from a barcode gun keyboard,", 0)
  say("repeated characters will be lost.", 20)
  if say(text, 80, (128, 255, 128)):
    text = ""
  pygame.display.flip()