[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
Re: [pygame] Key Presses
- To: pygame-users@xxxxxxxx
- Subject: Re: [pygame] Key Presses
- From: Nicholas Dudfield <ndudfield@xxxxxxxxx>
- Date: Tue, 19 Aug 2008 23:11:48 +1000
- Delivered-to: archiver@xxxxxxxx
- Delivered-to: pygame-users-outgoing@xxxxxxxx
- Delivered-to: pygame-users@xxxxxxxx
- Delivery-date: Tue, 19 Aug 2008 09:12:21 -0400
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from :user-agent:mime-version:to:subject:references:in-reply-to :content-type:content-transfer-encoding; bh=xH9Z5niDpLLwqS+ejwdR/tNQK0/zQ3rkwPEcAypLCNg=; b=TT+pLbyQGRh5zrW9O9Bj1jTPAkdI3OyEC4Ln469PRCOskPsTPQTQtSA8xOLtX1Kvi+ pOt/9Bp967Mno1DTK6k5B0fRtHOOOWHzHipJnC5a26NsmE7B3Jw/mRcpDvSroE0QJqPv Tcklymtg3wylYoLxoY0tKN86SP+cr04ASgPYk=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:subject:references :in-reply-to:content-type:content-transfer-encoding; b=TuF4+i/m6FBYYDjlY12JC6J58yLz6CYwb5aEnT4jKtEm4IogtueWcCSXXd4SmG5F9T rh29zvd2MOMN3bvLykjhi9JRKrbYU0Eml1215T9rvkehCFrFPRNlRPRC9U3CmRjPFQyq +GdVy/CxY5UZjy6fj4zS7j2WmApvQgtec1ra0=
- In-reply-to: <a62fab400808190310i276e9e7bpb5a2040c7ed39a2e@xxxxxxxxxxxxxx>
- References: <a62fab400808190310i276e9e7bpb5a2040c7ed39a2e@xxxxxxxxxxxxxx>
- Reply-to: pygame-users@xxxxxxxx
- Sender: owner-pygame-users@xxxxxxxx
- User-agent: Thunderbird 2.0.0.16 (Windows/20080708)
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