home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
The World of Computer Software
/
World_Of_Computer_Software-02-387-Vol-3of3.iso
/
s
/
s9302.zip
/
BRACHMAN.ZIP
/
SKEY.C
< prev
next >
Wrap
C/C++ Source or Header
|
1992-12-24
|
4KB
|
140 lines
/* S K E Y . C
┌───────────────────────────────────┐
│ ▐███▌ ████ ▀██████ █████ │
│ █████▐████▌ ▀████ █████ │
│ █▐████▌█████ ▀██ █████ │
│ ▐█▌█████▐████▌ ▄█ ▀ █████ │
│ ███▐████▌█████ ███ █████ │
│ ▐███▌█████▐████▌ ▀█ ▄ █████ │
│ █████▐████▌█████ ▄██ █████ │
│ ▐█████▌█████▐████▌ ▄████ █████ │
│ ███████▐████▌█████ ▄██████ █████ │
├───────────────────────────────────┤
│ Micro Endeavors, Inc. │
│ 3150 Township Line Road │
│ Drexel Hill, PA 19026 │
└───────────────────────────────────┘
demonstration 'C' library - adds the following:
skeyinit - arms keyboard for SEEK
skeykill - disables keyboard trap
author: Michael L. Brachman, Ph.D.
many thanks to George F. Goley, IV
*/
#include <dos.h>
#include <pro_ext.h>
/* global variables */
int skeyid;
Value val;
MHANDLE mh;
char *cp;
Point pt;
WHANDLE wh;
/* function predefinitions */
void dbback();
void dbseek(char);
FAR SKHandler(WHandle, EventRec FAR *);
/* initialization routine */
void FAR skeyinit(ParamBlk FAR *parm)
{
wh = _WOnTop(); /* get handle of window on top */
mh = _AllocHand(100); /* reserve some memory */
_HLock(mh); /* lock memory so it stays still */
val.ev_type = 'C'; /* define search string... */
val.ev_length = 0; /* ... as length 0 and ... */
val.ev_handle = mh; /* ... points to memory handle */
cp = _HandToPtr(mh); /* figure out real pointer too! */
/* now we attach our new event handler found below */
skeyid = _ActivateHandler(SKHandler);
}
/* removal routine, cleans up after itself */
void FAR skeykill(ParamBlk FAR *parm)
{
_HUnLock(mh); /* unlock and ... */
_FreeHand(mh); /* ... free memory */
/* remove our event handler from consideration */
_DeActivateHandler(skeyid);
}
/* this is the actual event handler ... */
/* ... it only looks at keyboard events for now */
FAR SKHandler(WHandle SWin, EventRec FAR *ev)
{
/* a return value of YES tells FoxPro that we trapped ... */
/* ... event and to proceed with next event. NO ... */
/* ... tells FoxPro that it should handle the current ... */
/* ... event */
int retval = NO;
if (ev->what == keyDownEvent) {
/* check to see if it is a legal character, upper case */
if ( (ev->message >= ' ' && ev->message < 'a') ||
(ev->message > 'z' && ev->message <= 0x7E) ) {
dbseek(ev->message);
retval = YES;
}
else { /* check for lower case too! */
if (ev->message >= 'a' && ev->message <= 'z') {
dbseek(ev->message & 0xDF); /* make upper case */
retval = YES;
}
else { /* and check for backspace as well */
if (ev->message == '\b') {
dbback();
retval = YES;
}
}
}
}
return retval;
}
/* this routine builds up a seek string by concatenating ... */
/* ... the character sent as an argument then doing a SEEK ... */
/* ... then printing the character to the window on top */
void dbseek(char chr)
{
val.ev_length += 1;
cp[val.ev_length-1] = chr; /* add char to string */
_DBSeek(&val);
pt.h = val.ev_length;
pt.v = 0;
_WPosCursor(wh,pt); /* position cursor in window */
_WPutChr(wh,chr); /* print character in window */
}
/* this routine erase 1 character if necessary and shortens ... */
/* ... the seek string and does a SEEK again */
void dbback()
{
if (val.ev_length > 0) {
pt.h = val.ev_length;
pt.v = 0;
_WPosCursor(wh,pt);
_WPutChr(wh,' '); /* erase last character typed */
val.ev_length -= 1;
_DBSeek(&val); /* seek against shorter string */
}
else /* no characters left to trin, ring the bell */
_PutChr(7);
}
FoxInfo myFoxInfo[] = {
{"SKEYINIT", skeyinit, 0, ""},
{"SKEYKILL", skeykill, 0, ""},
};
FoxTable _FoxTable = {
(FoxTable FAR *)0, sizeof(myFoxInfo) / sizeof(FoxInfo), myFoxInfo
};