DEFEVENT eventname eventprocedure
The DEFEVENT command attaches a Logo procedure to a specific event. Whenever this event occurs, the attached Logo procedure will be called. Its first input is a name which is the name of the event, while the second input is the name of the procedure which is to be attached to that event.
Currently, there are two events defined which you can overload. The BREAK event occurs every time the Control-G key is being pressed. Normally, a built-in event procedure will turn off the timer ticks (if a timer has been activated with the TIMER command) and return you to toplevel. You can modify this behaviour by defining an event procedure for the BREAK event. This procedure should, however, provide the option of returning to toplevel. If you omit this option, pressing Control-G will not return you to toplevel or even break any existing procedures. Also, you might want to turn off the timer during the event processing. The TIMER event is activated with the TIMER command. This command starts a timer which, when elapsed, generates a TIMER event which can be used to activate a Logo procedure. Both the BREAK and the TIMER events do not generate any inputs for the event handling procedures.
The following procedure is a replacement for the built-in BREAK handler. It will ask for confirmation of the break request before returning to toplevel.
- LOCAL "ANSWER
- PR "BREAK!
- TYPE [RETURN TO TOPLEVEL? |(Y/N)|]
- MAKE "ANSWER RC
- IF :ANSWER = "Y THEN \
- IGNORE TIMER "FALSE \
- (HALT) \
? DEFEVENT "BREAK "MY.OWN.BREAK