In a typical C program for the Palm OS, the body of the program is an event handling loop that processes events from the operating system and takes required actions, such as passing events to the system for default handling, initializing forms, etc.
In a Quartus Forth application, you don't need to worry about handling most events; they're handled for you whenever you use KEY or EKEY. Quartus Forth automatically handles:
Events not automatically handled are returned on the Forth stack via EKEY, where you can read them and take any desired action.
Here is a code snippet showing how to detect events using EKEY. It will detect stylus taps on the LCD screen:
needs events
: go ( -- )
begin ekey
dup penDownEvent = if
." Pen Down detected" cr
else dup penUpEvent = if
." Pen Up detected" cr
then
then drop
again ;
Of special interest is how appStopEvents are handled. Quartus Forth gives you full control over what happens when your application exits. When Quartus Forth (or a stand-alone Quartus Forth application) receives an appStopEvent from the system, a -257 THROW code is generated. Under normal conditions, this THROW code will be caught by the default exception handler, and the application will simply exit via (bye); you may, however wish to CATCH this exception code and take care of any required cleanup before calling (bye) yourself.
This code snippet shows an example of special BYE handling:
-257 constant byeThrow
: go ( -- )
MainForm
." Go ahead, start another app." cr
begin
['] key catch
byeThrow = if
." Exiting in 5 seconds!"
500. SysTaskDelay
(bye)
then drop
again ;
Event # | Event Type |
0 | nilEvent |
1 | penDownEvent |
2 | penUpEvent |
3 | penMoveEvent |
4 | keyDownEvent |
5 | winEnterEvent |
6 | winExitEvent |
7 | ctlEnterEvent |
8 | ctlExitEvent |
9 | ctlSelectEvent |
10 | ctlRepeatEvent |
11 | lstEnterEvent |
12 | lstSelectEvent |
13 | lstExitEvent |
14 | popSelectEvent |
15 | fldEnterEvent |
16 | fldHeightChangedEvent |
17 | fldChangedEvent |
18 | tblEnterEvent |
19 | tblSelectEvent |
20 | daySelectEvent |
21 | menuEvent |
22 | appStopEvent |
23 | frmLoadEvent |
24 | frmOpenEvent |
25 | frmGotoEvent |
26 | frmUpdateEvent |
27 | frmSaveEvent |
28 | frmCloseEvent |
29 | frmTitleEnterEvent |
30 | frmTitleSelectEvent |
31 | tblExitEvent |
32 | sclEnterEvent |
33 | sclExitEvent |
34 | sclRepeatEvent |
32767 | firstUserEvent |