Adding+an+event+to+the+event+queue

//by Richard Russell, August 2014//

Normally, **event interrupts** (e.g. ON MOUSE, ON MOVE, ON SYS and ON TIME) take place as a result of user actions such as mouse clicks, menu selections, moving/re-sizing a window or (in the case of ON TIME) periodically. The events are initially added to a 32-event FIFO queue, and then automatically dispatched to the specified BASIC handler routine (if any).

For test purposes, or other special uses, it is possible to insert a 'pseudo event' into the queue (if there is enough space). You can do that using the following code: code format="bb4w" SYS @fn%(18), handler%, msg%, wparam%, lparam% @flags% OR= &20000000 code Here **handler%** is the address of the event handler (see below), **msg%** is the value which will ultimately be received by the handler in the **@msg%** system variable, **wparam%** is the value which will be received in **@wparam%** and **lparam%** is the value which will be received in **@lparam%**.

The **handler%** parameter can be the address of a custom handler or can specify one of the standard ON... event handlers as follows: code format="bb4w" handler%=!388 : REM ON TIME handler%=!396 : REM ON MOVE handler%=!400 : REM ON SYS handler%=!404 : REM ON MOVE code (if no relevant **ON event** statement has yet been executed, or an **ON event OFF** has been executed, handler% will be set to zero).

If you want to determine whether the event was successfully added to the queue you can test the return value: code format="bb4w" SYS @fn%(18), handler%, msg%, wparam%, lparam% TO ok% IF ok% @flags% OR= &20000000 code If **ok%** is non-zero the event was added, if it is zero the queue was already full.

Here is a simple example of the use of this technique: code format="bb4w" ON SYS PRINT @msg%,@wparam%,@lparam% : RETURN

SYS @fn%(18), !400, 123, 456, 789 TO ok% IF ok% @flags% OR= &20000000

REPEAT WAIT 0 UNTIL FALSE code