[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
RE: [pygame] Key Presses
Use the .unicode property on the event.
--Noah
> -----Original Message-----
> From: owner-pygame-users@xxxxxxxx [mailto:owner-pygame-users@xxxxxxxx]
> On Behalf Of Nicholas Dudfield
> Sent: Tuesday, August 19, 2008 6:12 AM
> To: pygame-users@xxxxxxxx
> Subject: Re: [pygame] Key Presses
>
> Ian,
>
> In [1]: import pygame
>
> In [2]: pygame.K_QUESTION
> Out[2]: 63
>
> In [3]: chr(pygame.K_QUESTION)
> Out[3]: '?'
>
> In [4]: chr(pygame.K_TAB)
> Out[4]: '\t'
>
> http://www.pygame.org/docs/ref/key.html
>
> """
> There are many keyboard constants, they are used to represent keys on
> the keyboard. The following is a list of all keyboard constants
>
> KeyASCII ASCII Common Name
> K_BACKSPACE \b backspace
> K_TAB \t tab
> K_CLEAR clear
> K_RETURN \r return
> K_PAUSE pause
> K_ESCAPE ^[ escape
> K_SPACE space
> K_EXCLAIM ! exclaim
> K_QUOTEDBL " quotedbl
> K_HASH # hash
> K_DOLLAR $ dollar
> K_AMPERSAND & ampersand
> K_QUOTE quote
> K_LEFTPAREN ( left parenthesis
> K_RIGHTPAREN ) right parenthesis
> K_ASTERISK * asterisk
> K_PLUS + plus sign
> K_COMMA , comma
> K_MINUS - minus sign
> K_PERIOD . period
> K_SLASH / forward slash
> .....
>
> K_SEMICOLON ; semicolon
> K_LESS < less-than sign
> K_EQUALS = equals sign
> K_GREATER > greater-than sign
> K_QUESTION ? question mark
>
> """
>
> Cheers.
>
>
> Ian Mallett wrote:
> > Hello,
> >
> > This should be a pretty simple question.
> >
> > I have a 3D multiplayer game where there is a chat box for
> > communication, and I am at the part where the message is entered.
> > Here is my relevant code so far:
> >
> >
> > key = pygame.key.get_pressed()
> > ...
> > for event in pygame.event.get():
> > ...
> > if event.type == KEYDOWN:
> > ...
> > elif event.key == K_BACKSPACE and TypingMessage:
> > Message = Message[:-1]
> > elif TypingMessage:
> > name = pygame.key.name
> <http://pygame.key.name>(event.key)
> > if len(name) == 1:
> > if key[K_LSHIFT] or key[K_RSHIFT]:
> > name = name.upper()
> > if key[K_CAPSLOCK]:
> > name = name.swapcase()
> > Message += name
> >
> >
> > Unfortunately, this cannot do cases where the uppercase character is
> > completely different from the lowercase character (for example, "?"
> > and "/"). This is exactly the problem.
> >
> > I looked into the documentation, but I wasn't able to make out how
> > this could be fixed as there were no relevant examples.
> >
> > Thanks,
> > Ian