def inputhook_pyglet():
<EOL>try:<EOL><INDENT>t = clock()<EOL>while not stdin_ready():<EOL><INDENT>pyglet.clock.tick()<EOL>for window in pyglet.app.windows:<EOL><INDENT>window.switch_to()<EOL>window.dispatch_events()<EOL>window.dispatch_event('<STR_LIT>')<EOL>flip(window)<EOL><DEDENT>used_time = clock() - t<EOL>if used_time > <NUM_LIT:5>*<NUM_LIT>:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL><DEDENT>elif used_time > <NUM_LIT>:<EOL><INDENT>time.sleep(<NUM_LIT:1.0>)<EOL><DEDENT>elif used_time > <NUM_LIT:0.1>:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL><DEDENT>else:<EOL><INDENT>time.sleep(<NUM_LIT>)<EOL><DEDENT><DEDENT><DEDENT>except KeyboardInterrupt:<EOL><INDENT>pass<EOL><DEDENT>return <NUM_LIT:0><EOL>
Run the pyglet event loop by processing pending events only.

    This keeps processing pending events until stdin is ready.  After
    processing all pending events, a call to time.sleep is inserted.  This is
    needed, otherwise, CPU usage is at 100%.  This sleep time should be tuned
    though for best performance.