Pen InputDetecting when the screen has been
tapped by the pen is fairly easy using GetEvent32.
However, there are side effects. One potential problem is
that GetEvent32 stops the program until an event occurs
(rather like Get). Normally this is OK though.
A second problem is that
lots of events are returned, such as a keypress, or the
program moving to the foreground or background, the Psion
being switched on and so on. Luckily, you can ignore many
events and just respond to the ones you want.
The program here responds
to pen taps and key presses. You first need to declare an
array of long integers since this is used by GetEvent32
to return the results of the event.
A good choice is
ev&(32).
Call GetEvent32, passing
it the array. The program then prints the event code,
returned in ev&(1), in hexadecimal. Why? It's easier
that way. If ev&(1)=&408 then a pen event has
occurred. We don't know what sort of pen event it is
though, so we check ev&(4), which can be either 0
(pen down), 1 (pen up) or 6 (drag). The program below
just checks for 0 and 1.
Assuming it is a pen
event, the following information is returned in the
ev&() array:
ev&(1) = &408
ev&(3) = window ID
ev&(4) = (see below)
ev&(6) = x-co-ordinate
ev&(7) = y-co-ordinate
And ev&(4) has one of the following values:
0 = pen down
1 = pen up
6 = drag
Other values are returned,
but they aren't important. Now we know when the pen taps
the screen and can read the x,y coordinate. It's up to
you what you do with this information. One thing you
could do is check to see whether the x,y coordinates lie
within some object on the screen and take appropriate
action.
While we're using
GetEvent32 I might as well mention that a keypress is
indicated by the expression (ev&(1) and &400)=0.
If this expression is true, then the key code is stored
in ev&(1). It's worth pressing a few keys - try a,
and Ctrl+a, the menu key and so on - and see the values
returned:
PROC peninput:
Global ev&(32)
At 1,1 : Print "Press a key/tap the screen... Press s to stop"
While 1
Getevent32 ev&() Rem Wait for an event
At 1,3 : Print "Event code = ";Hex$(ev&(1));" "
If ev&(1)=&408 And ev&(4)<2 Rem Pen down event
At 1,5 : Print "x = ";ev&(6),"y = ";ev&(7);" "
Endif
If (ev&(1) And &400)=0 Rem Keypress
At 1,7 : Print "Key pressed = ";ev&(1);" ";
If ev&(1)=%s : stop : Endif
Endif
Endwh
ENDP
|