Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Key checking in the update function and on_key_press
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  10 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Wallace Davidson  
View profile  
 More options Oct 10 2012, 11:34 pm
From: Wallace Davidson <wallace...@gmail.com>
Date: Wed, 10 Oct 2012 20:34:54 -0700 (PDT)
Local: Wed, Oct 10 2012 11:34 pm
Subject: Key checking in the update function and on_key_press

Is it possible to have both of these in a program? I have:

@window.event
def on_key_press(symbol, modifiers):
    if symbol == key.ESCAPE:
    return pyglet.event.EVENT_HANDLED

def update(dt):
    if keys[key.W]:
        print "hi"
        code....

But only the on_key_press function is recognised. Would it be better to
have one or the other?


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Oct 11 2012, 4:59 am
From: Adam Bark <adam.jt...@gmail.com>
Date: Thu, 11 Oct 2012 09:59:04 +0100
Local: Thurs, Oct 11 2012 4:59 am
Subject: Re: Key checking in the update function and on_key_press

On Oct 11, 2012 4:34 AM, "Wallace Davidson" <wallace...@gmail.com> wrote:

> Is it possible to have both of these in a program? I have:

> @window.event
> def on_key_press(symbol, modifiers):
>     if symbol == key.ESCAPE:
>     return pyglet.event.EVENT_HANDLED

> def update(dt):
>     if keys[key.W]:
>         print "hi"
>         code....

> But only the on_key_press function is recognised. Would it be better to

have one or the other?


If you're handling key presses you should use the appropriate event
handler. Anything that needs to be run that isn't a user input event e.g.
simulation should be scheduled with pyglet.clock.schedule, schedule_once or
schedule_interval

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 11 2012, 11:10 am
From: Nathan <nathan.sto...@gmail.com>
Date: Thu, 11 Oct 2012 09:10:33 -0600
Local: Thurs, Oct 11 2012 11:10 am
Subject: Re: Key checking in the update function and on_key_press

On Wed, Oct 10, 2012 at 9:34 PM, Wallace Davidson <wallace...@gmail.com>wrote:

> Is it possible to have both of these in a program? I have:

> @window.event
> def on_key_press(symbol, modifiers):
>     if symbol == key.ESCAPE:
>     return pyglet.event.EVENT_HANDLED

> def update(dt):
>     if keys[key.W]:
>         print "hi"
>         code....

> But only the on_key_press function is recognised. Would it be better to
> have one or the other?

That is certainly possible, you just need to schedule the update(dt)
function to be called -- it's not an event handler that's automatically
handling some event like on_key_press(...) is.

Though as Adam already alluded to, just because it's possible doesn't mean
it's necessarily the best way to do it.

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wallace Davidson  
View profile  
 More options Oct 11 2012, 4:23 pm
From: Wallace Davidson <wallace...@gmail.com>
Date: Fri, 12 Oct 2012 09:22:50 +1300
Local: Thurs, Oct 11 2012 4:22 pm
Subject: Re: Key checking in the update function and on_key_press

I had thought the on_key_press one was to check when a key was pressed and
the update function checked whether a key was held down. Is that right? :/


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Jones  
View profile  
 More options Oct 11 2012, 6:36 pm
From: Richard Jones <r1chardj0...@gmail.com>
Date: Fri, 12 Oct 2012 09:36:54 +1100
Local: Thurs, Oct 11 2012 6:36 pm
Subject: Re: Key checking in the update function and on_key_press
On 11 October 2012 14:34, Wallace Davidson <wallace...@gmail.com> wrote:

> Is it possible to have both of these in a program? I have:

> @window.event
> def on_key_press(symbol, modifiers):
>     if symbol == key.ESCAPE:
>     return pyglet.event.EVENT_HANDLED

> def update(dt):
>     if keys[key.W]:
>         print "hi"
>         code....

> But only the on_key_press function is recognised. Would it be better to have
> one or the other?

You don't show it - did you push the keys handler (which I assume is a
KeyStateHandler) onto the window event handlers?

    Richard


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Nathan  
View profile  
 More options Oct 11 2012, 6:37 pm
From: Nathan <nathan.sto...@gmail.com>
Date: Thu, 11 Oct 2012 16:37:52 -0600
Local: Thurs, Oct 11 2012 6:37 pm
Subject: Re: Key checking in the update function and on_key_press

On Thu, Oct 11, 2012 at 2:22 PM, Wallace Davidson <wallace...@gmail.com>wrote:

> I had thought the on_key_press one was to check when a key was pressed and
> the update function checked whether a key was held down. Is that right? :/

No.

The update function is just a function.  If you want it to be called, you
need to make something call it.

~ Nathan


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wallace Davidson  
View profile  
 More options Oct 11 2012, 6:42 pm
From: Wallace Davidson <wallace...@gmail.com>
Date: Fri, 12 Oct 2012 11:42:40 +1300
Local: Thurs, Oct 11 2012 6:42 pm
Subject: Re: Key checking in the update function and on_key_press

Yes, I've got this:

keys = key.KeyStateHandler()
window.push_handlers(keys)

That makes sense now, thanks for the help guys :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Wallace Davidson  
View profile  
 More options Oct 11 2012, 6:44 pm
From: Wallace Davidson <wallace...@gmail.com>
Date: Fri, 12 Oct 2012 11:44:49 +1300
Local: Thurs, Oct 11 2012 6:44 pm
Subject: Re: Key checking in the update function and on_key_press

I've added this:

pyglet.clock.schedule_interval(update, 1/60.0)

and it's working fine

On Fri, Oct 12, 2012 at 11:42 AM, Wallace Davidson <wallace...@gmail.com>wrote:


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Adam Bark  
View profile  
 More options Oct 11 2012, 7:25 pm
From: Adam Bark <adam.jt...@gmail.com>
Date: Fri, 12 Oct 2012 00:25:03 +0100
Local: Thurs, Oct 11 2012 7:25 pm
Subject: Re: Key checking in the update function and on_key_press

On 11/10/12 21:22, Wallace Davidson wrote:

Personally, I set a flag in on_key_press and unset it in on_key_release.

 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Richard Jones  
View profile  
 More options Oct 11 2012, 8:04 pm
From: Richard Jones <r1chardj0...@gmail.com>
Date: Fri, 12 Oct 2012 11:04:24 +1100
Local: Thurs, Oct 11 2012 8:04 pm
Subject: Re: Key checking in the update function and on_key_press
On 12 October 2012 10:25, Adam Bark <adam.jt...@gmail.com> wrote:

> Personally, I set a flag in on_key_press and unset it in on_key_release.

That's all that KeyStateHandler does. It manages those flags for you :-)

     Richard


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »