Hello,
So the dispatch_event works great, but now I can't seem to get it to work with unittest, nose or py.test.
I have the following code in my py.test file:


import pyglet
k = pyglet.window.key
my_app = pyglet.app
window = pyglet.window.Window(caption="Test app")

def setup_module(module):
    my_app.run()

def teardown_module(module):
    my_app.exit()

def test_keys():
    r = False
    def on_key_press(key, mods):
        if key == k.A:
            r = True
    window.push_handlers(on_key_press)
    window.dispatch_event('on_key_press', k.A, 0)
    assert r == True


When it runs, it says that r is False.
Also, the window does not close. Does anyone know why this is?
thanks,

Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 3/14/2015 11:57 AM, Brandon Keith Biggs wrote:
Hello,
You need to just enter the same amount of args as you would if it was calling the function. For example:
my_app.dispatch_event('on_key_press', k.A, 0)
will press a.
Thank you,

Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
On 3/14/2015 11:48 AM, Rob wrote:
Hi,

I think the 'on_key_press' is an event for Window, so you need to dispatch it on the window object you want to simulate key presses for. The second argument contains the modifiers like ctrl and alt. So 0 if there is no modifier or a combination of pyglet.window.key.MOD_*

Rob


Op vrijdag 13 maart 2015 22:06:43 UTC+1 schreef Brandon Keith Biggs:

    Hello,
    That looks like it would work, but I can't figure out how it
    works. Here is what my line looks like:
            my_app.dispatch_event('on_key_press', pyglet.window.key.A)

    But that gives me an error. I'm not sure what to put as the
    second argument.
    thank you,

    Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>
    On 3/13/2015 10:26 AM, Rob wrote:
    If it is to test your own code, you could use
    window.dispatch_event(...) to manually trigger the events.

    Rob

    Op donderdag 12 maart 2015 08:45:42 UTC+1 schreef Brandon Keith
    Biggs:

        Hello,
        Is there a way to tell pyglet that there was a key press
        from an automated script through pyglet?
        Or do I need to go to an external library?
        thanks,

-- Brandon Keith Biggs <http://www.brandonkeithbiggs.com/>

-- You received this message because you are subscribed to the
    Google Groups "pyglet-users" group.
    To unsubscribe from this group and stop receiving emails from
    it, send an email to [email protected] <javascript:>.
    To post to this group, send email to [email protected]
    <javascript:>.
    Visit this group at http://groups.google.com/group/pyglet-users
    <http://groups.google.com/group/pyglet-users>.
    For more options, visit https://groups.google.com/d/optout
    <https://groups.google.com/d/optout>.

--
You received this message because you are subscribed to the Google Groups "pyglet-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected] <mailto:[email protected]>. To post to this group, send email to [email protected] <mailto:[email protected]>.
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pyglet-users.
For more options, visit https://groups.google.com/d/optout.

Reply via email to