Code | Description |
---|---|
0 | Nothing happened |
1 | Mouse button pressed |
-1 | Mouse button released |
2 through 255 | Keyboard button pressed, see http://keycode.info/ |
-2 through -255 | Keyboard button released |
255 or more | Touch start |
-255 or less | Touch end |
Mouse differs from touch in the event code: for mouse, it is always 1.
1. Store the touch identifier using GET: GET EVCODE
2. Use that touch identifier to index the TOUCHX and TOUCHY arrays: X = TOUCHX(EVCODE):Y = TOUCHY(EVCODE)
3. Check if X is negative. -1 signals that the touch event has been canceled.
Whenever a keystroke or touch/mouse button event happens, the code of the event is put on the event queue. When the program runs a GET instruction, the oldest event will be taken from that event queue. GET assigns 0 only if the event queue is empty.
You'll need a main loop. It's main because it runs all the time while the program is expecting user interaction.
Main loop should have one WAIT instruction in its body and a GET. This enables that every event will be processed within 20 millisecs (although it does not ensure, think of long lasting calculations done in the loop or a burst of events.)
With two WAITs instead of one, you'll get more relaxed CPU and 40-millisecond reaction time, which happens to be the screen refresh rate. So if the reaction deals with animation on screen, it normally does the trick.
Note that there is no multithreading or even interrupt handling in an imeight program, so the main loop is pretty much your only option handling events.
Two options to implement the main loop:
* Start with @MAINLOOP
and end with GOTO @MAINLOOP
* Start with FOR MLC=0 TO 1 STEP 0
and end with NEXT MLC
, see Sample Programs
Anonymous