WaitEvent ( [timeout] )
Parameters
|
timeout (optional) - how long to wait, in milliseconds: -1: wait until an event arrives (default) 0: return immediately above 0: wait up to that many milliseconds |
Description
|
Waits for the next event, makes it current and returns its id - or 0 if the wait timed out. Requires Extended language mode. This is the heartbeat of a GUI program. It takes the next event off the shared queue - a button click, a key press, a menu pick, a window close - makes it the current event for EventID, EventData, EventX, EventY, EventZ and EventSource, and returns its id. If the queue is empty it sleeps until something happens, so an idle tool uses no CPU. While it waits, the GUI stays fully alive: windows can be dragged, resized and repainted, because native messages keep being processed. Your Blitz code simply does not run again until an event (or the timeout) wakes it. A timeout turns the wait into a paced loop - WaitEvent(16) is a handy way to keep a mostly idle tool ticking - and 0 makes it a pure poll. For a program that renders every frame, though, reach for PeekEvent instead; it never sleeps. Each event is delivered exactly once: whichever of WaitEvent and PeekEvent fetches it removes it from the queue. Every GUI sample is built around this call - the window and button sample shows the smallest loop, and the world editor shell sample a full editor's version. See also: PeekEvent, EventID, EventData, EventSource, FlushEvents. |
Index