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

Re: [pygame] Newbie needs help, what's the most efficient (or easiest) way to do this?



Charles Christie wrote:
Sorry for spamming your email inboxes so much guys... I'm bad at this
whole email list thing... I'm better with forums, because I can edit
messages I post and stuff. Eh... Sorry.

Anyway, now I want the Textsprite class to not accept input while the
K_TAB button is pressed.

What would I have to code in this situation? I know that the program,
upon pressing TAB, should not negatively effect score (I've already
coded that part) but I don't know how to get it to actually stop
advancing the pointer as long as the TAB button is held down. I think
its because the advice I got was for an older version of pygame and
its not working.
Not sure what you mean about the old version...
I am using a dvorak keyboard, therefore my typing speed is quite hampered while my mind learns the new layout.
So my reply will be short. Didn't want you to think I was being disrespectful.


Okay, basically the problem you have is that you want to do something when the tab key's state is raised, and something else when its state is depressed.
This suggests an if/else structure, because the key can only be in two states: depressed or not.


now how do we determine the state of the key? like this:

tab_pressed = False#set this once, outside your game loop, not on each iteration
for event in pygame.event.get():
if event.type == KEYDOWN:
if event.key == K_TAB:
tab_pressed = True
else:
#call your function here
elif event.type == K_UP:
if event.key == K_TAB:
tab_pressed = False


you'd probably want to add tab_pressed to your argument list for your keyin function.
-Luke