Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : CLICKMON.C

 
Output of file : CLICKMON.C contained in archive : PCTJ8805.ZIP
/* ClickMon.C Illustration of a simple OS/2 keyboard monitor.
Monitors the keyboard and makes a click on each key press.

To compile: CL -Lp -Zp clickmon.c
To execute: DETACH CLICKMON
To remove: Press [Esc] while in its screen group.
*/

#include
#include

#define ESCAPE 27
#define RELEASE 0x40 /* Kp.ddflags bit indicates key release */

struct KeyPacket { /* keyboard monitor data record */
unsigned monflags;
char ascii;
char scan;
char idontcare[8];
unsigned ddflags;
} Kp; /* allocate storage for one packet */

char InBuf[128]; /* buffers used for keyboard monitoring */
char OutBuf[128]; /* hard-coding the size for simplicity */

main()
{
unsigned monhandle, kplen, index;

DOSMONOPEN ( "KBD$", &monhandle ); /* get a monitor handle */

InBuf[0]=128; InBuf[1]=0; /* setup size for DOSMONREG */
OutBuf[0]=128; OutBuf[1]=0;
index = CurGrp(); /* get current screen group id */

DOSMONREG( monhandle, InBuf, OutBuf, 1, index );

/* ============= Monitor Read/Process/Write Loop ============ */
while ( 1 ) {
kplen = sizeof(Kp);
DOSMONREAD( InBuf, 0, (char *)&Kp, &kplen ); /* read packet */
if ( Kp.ascii == ESCAPE ) { /* ESC to kill the monitor */
DOSMONCLOSE( monhandle );
DOSEXIT ( 1, 0 );
}
if ( (Kp.ddflags & RELEASE) == 0 ) /* if not a key release */
DOSBEEP( 250, 35 ); /* packet, make a click */

DOSMONWRITE( OutBuf, (char *)&Kp, kplen ); /* write packet */
}
}

/* ============ This obtains the ID of the current screen group ==
The byte at offset 24 in the InfoSeg is the current screen group.
This function just extracts that one value.
*/

CurGrp()
{
unsigned infoseg, localseg, cg;
char far *gdt;

DOSGETINFOSEG( &infoseg, &localseg );
gdt = (char far *)( (long)infoseg << 16 );
return( gdt[24] );
}


  3 Responses to “Category : Files from Magazines
Archive   : PCTJ8805.ZIP
Filename : CLICKMON.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/