[visionegg] Re: converting pygame constants to characters

  • From: Gabriel Nevarez <nevarezg@xxxxxxxx>
  • To: visionegg@xxxxxxxxxxxxx
  • Date: Thu, 24 Feb 2005 19:44:38 +0000

I looked at it without trying it out yet... in the example case given, I didn't know if it actually returned 'space' or whether it actually returned a space char.

As strings are immutable in python, i'm using character arrays for text input (since I need to be able to add and delete characters in the text buffer without having to create a new string for each entry). Per the pygame docs, the pygame.key.name() method returns a string. Perhaps the right question was, then, how to convert a string to a char.

-=gabe


Hi Gabriel -

It sounds like you're looking for pygame.key.name():
http://www.pygame.org/docs/ref/pygame_key.html

cheers...
  -- jascha

On Wed, 23 Feb 2005, Gabriel Nevarez wrote:

 Hello all,

 This is more a pygame issue than VisionEgg, but here goes anyway...

 As the GUI functions aren't working on OS X, I'm writing my own
 dialog box input routines.

 As such, I'm checking for valid input using the pygame.event.poll()
 method, and checking against the pygame constants.

 Is there a quick-and-dirty way of converting pygame constants to
 their appropriate character representations?

 Otherwise, it's a case of writing a functions such as:

 def convertKeypressToChar(keypress):
      pl = pygame.locals
      if keypress == pl.K_0:
          return '0'
      elif keypress == pl.K_1:
          return '1'
      elif keypress == pl.K_2:
          return '2'
      elif keypress == pl.K_3:
          return '3'
      elif keypress == pl.K_4:
          return '4'
      elif keypress == pl.K_5:
          return '5'
 (and so forth, for EACH key....)

 Any ideas?

 -=Gabriel Nevarez
 Research Programmer
 Psychology Department
 Cardiff University
 http://www.cf.ac.uk/psych

 ======================================
 The Vision Egg mailing list
 Archives: //www.freelists.org/archives/visionegg
 Website: http://www.visionegg.org/mailinglist.html


====================================== The Vision Egg mailing list Archives: //www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html

====================================== The Vision Egg mailing list Archives: //www.freelists.org/archives/visionegg Website: http://www.visionegg.org/mailinglist.html

Other related posts: