Using adsPen is simple. You need to call just one function:
int adsPenInput(INPUT_EVENT pEventFunction);
And you implement just one event function:
typedef int (* INPUT_EVENT) (int Reason, char Code, byte Mode);
adsPenInput registers the event and passes the flow
control to the strokes recognizer. The recognizer loops
undefinetely and fires the event everytime a character is recognized.
When pEventFunction is called Reason is the reason
why the event is fired:
- ADSPEN_REASON_CODE
- ADSPEN_REASON_MODE
ADSPEN_REASON_CODE informs that a characters is delivered and its
ascii code is the value of Code. ADSPEN_REASON_MODE reason
notifies on a mode change (shift is (un)selected) so that the program
can update a visual indicator. Mode parameter is a bitset
and may be checked against:
- ADSPEN_MODE_SHIFT
- ADSPEN_MODE_SLOCK (not implemented)
The user quits the recognizer by pressing 'esc' or pushing the lever
up. You can also terminate the recognizer according to some software
condition.
The return value of pEventFunction tells the recognizer
whether to go on or stop. Just return ADSPEN_CMD_EXIT to quit
the recognizer, if you want to wait for the next character
you must return ADSPEN_CMD_NEXT.
Special codes:
- 13 is Enter
- 17 is Up
- 18 is Down
- 19 is Left
- 20 is Right
- 127 is Del
Scenario:
int InputEvent(int Reason, char Code, byte Mode)
{
/* Handle Shift Event */
if (Reason == ADSPEN_REASON_MODE)
{
if (Mode & (ADSPEN_MODE_SHIFT | ADSPEN_MODE_SLOCK)) ...
}
/* Handle Normal Input */
if (Reason == ADSPEN_REASON_CODE)
{
if (isprint(Code)) ...
}
return ADSPEN_CMD_NEXT;
}
.
.
.
adsPenInput(InputEvent);
|