|
|
For a sample virtual key mapping, consider ``A sample key virtualization routine'', which contains the application-defined function get_request. Most of the values returned by get_request are ETI form requests defined in header file form.h and described in the next section. The other values returned (in this example, only value QUIT are defined by the application program treated in ``Calling the form driver''.
/* The following key mapping is defined by get_request. Note that ^X represents the character control-X.^Q - end form processing
^F - move to next page ^B - move to previous page ^N - move to next field ^P - move to previous field home key - move to first field home down - move to last field ^L - move left to field ^R - move right to field ^U - move up to field ^D - move down to field
^W - move to next word ^T - move to previous word ^S - move to beginning of field data ^E - move to end of field data left arrow - move left in field right arrow - move right in field down arrow - move down in field up arrow - move up in field
^M <CR> - enter new line ^I - insert blank character ^O - insert blank line ^V - delete character ^H <BS> - delete previous character ^Y - delete line ^G - delete word ^C - clear to end of line ^K - clear to end of field ^X - clear entire field ^A - request next field choice ^Z - request previous field choice ESC - toggle between insert and overlay mode
define application commands */
#define QUIT (MAX_COMMAND + 1)
static int get_request (w) /* virtual key mapping */ WINDOW * w; { static int mode = REQ_INS_MODE; int c = wgetch (w); /* read a character */
switch (c) { case 0x11: /* ^Q */ return QUIT;
case 0x06: /* ^F */ return REQ_NEXT_PAGE; case 0x02: /* ^B */ return REQ_PREV_PAGE; case 0x0e: /* ^N */ return REQ_NEXT_FIELD; case 0x10: /* ^P */ return REQ_PREV_FIELD; case KEY_HOME: return REQ_FIRST_FIELD; case KEY_LL: return REQ_LAST_FIELD; case 0x0c: /* ^L */ return REQ_LEFT_FIELD; case 0x12: /* ^R */ return REQ_RIGHT_FIELD; case 0x15: /* ^U */ return REQ_UP_FIELD; case 0x04: /* ^D */ return REQ_DOWN_FIELD; case 0x17: /* ^W */ return REQ_NEXT_WORD; case 0x14: /* ^T */ return REQ_PREV_WORD; case 0x13: /* ^S */ return REQ_BEG_FIELD; case 0x05: /* ^E */ return REQ_END_FIELD; case KEY_LEFT: return REQ_LEFT_CHAR; case KEY_RIGHT: return REQ_RIGHT_CHAR; case KEY_DOWN: return REQ_DOWN_CHAR; case KEY_UP: return REQ_UP_CHAR; case 0x0d: /* ^M */ return REQ_NEW_LINE; case 0x09: /* ^I */ return REQ_INS_CHAR; case 0x0f: /* ^O */ return REQ_INS_LINE; case 0x16: /* ^V */ return REQ_DEL_CHAR; case 0x08: /* ^H */ return REQ_DEL_PREV; case 0x19: /* ^Y */ return REQ_DEL_LINE; case 0x07: /* ^G */ return REQ_DEL_WORD; case 0x03: /* ^C */ return REQ_CLR_EOL; case 0x0b: /* ^K */ return REQ_CLR_EOF; case 0x18: /* ^X */ return REQ_CLR_FIELD; case 0x01: /* ^A */ return REQ_NEXT_CHOICE; case 0x1a: /* ^Z */ return REQ_PREV_CHOICE; case 0x1b: /* ESC */ if (mode == REQ_INS_MODE) return mode = REQ_OVL_MODE; else return mode = REQ_INS_MODE; } return c; }
A sample key virtualization routine
In get_request, only a subset of the requests are defined so that the requests your end-user can make are limited. If you like, you can also map two or more keys onto one request. This is helpful where some terminals lack one of the keys in question. In that case, the user can press the other key to the same effect.
Function get_request first sets the data entry mode for the end-user. Here it is set initially to insert mode. The last case statement in the routine enables your end-user to press the escape key <ESC> to switch to overlay mode. Both modes are discussed in ``Field editing requests''.
Next, get_request calls wgetch to read a character entered by the user. The switch statement maps the character read onto a specific application command or form request. The application command QUIT appears here as the first case; the other cases map characters onto form requests. Any character that is not an application command or form request is simply returned unchanged--it is treated as data being entered into the current field.
Note that this key mapping assumes your end-user will be using a terminal with arrow keys (KEY_LEFT, KEY_RIGHT, KEY_UP, KEY_DOWN), a home key (KEY_HOME), and a home down key (KEY_LL).