In the pyglet docs, I found:
The following example shows how to grab a screenshot of your application window:
pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')
However when using this, everything will stop until I click the mouse. Is there another way to get the screen contents in Pyglet, or to force it back into the event loop?
EDIT: I have found that actually there is a short delay (0.2 seconds~), but nothing else. Actually it is something to do with the F10 key that stops pyglet. >_>
I cannot close or delete since there is an open bounty.
Okay, here is a complete working example in pyglet. It shows the text "hello world" taking a random walk around the window and dumps the screenshot (using the exact same line of code you posted) every time you press a key.
Taking the screenshot doesn't halt the event loop. The event loop in pyglet is just lazy, and tries to do as little work as possible. You need to schedule a function to run repeatedly if you want things to keep happening on their own. Otherwise, it'll wait for an event that has a listener attached to happen. (Your code must be listening for the mouse event, which is why it resumes work when you click the mouse.)
Short answer, I suspect the fix you need is
pyglet.clock.schedule_interval(...)
.