home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
GETSCRN.EXE
/
SOURCE
/
MONITOR.C
< prev
next >
Wrap
Text File
|
1990-06-24
|
5KB
|
189 lines
/*
MONITOR.c
Copyright (c) 1990 by: Arthur Kevin McGrath
Contract Engineers
P. O. Box 128
Barboursville, VA 22923
703/832-7025
ALL RIGHTS ARE RESERVED. You may not copy this program in any way
except to make back-up copies FOR YOUR OWN USE. If you copy this
program for any reason without WRITTEN PERMISSION from the above
named copyright owner (except to make back-up copies FOR YOUR OWN USE),
you are breaking the Copyright Laws of the United States. You will go
to jail for one year and pay a $50,000 fine.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#define INCL_BASE
#define INCL_VIO
#include <os2.h>
#include "capture.h"
#include "extern.h"
#define DEFAULT 0
#define END_KEY 0x75
#define PRINT_SCREEN 0x72
struct kbd_packet
{
USHORT monitor_flag;
KBDKEYINFO c;
ULONG time;
USHORT device_driver_flag;
};
/* MONITOR_THE_KEYBOARD() will pass every character that comes from
the keyboard untill it sees an <CONTROL><PRINT SCREEN> keystroke
or a <CONTROL><END> keystroke.
At that time, it will:
1. eat the <CONTROL><PRINT SCREEN> keystroke so that it
goes no further
(Scan Code 0x72 Character Code 0x00 )
2. Capture the Physical Screen Buffer to a file of
the user's choice
or
3. END the monitor when it receives a <CONTROL><END>
keystroke.
(Scan Code 0x75 Character Code 0x00 or 0xE0)
Only one buffer capture can be active at any one time. This
function shall guarantee that the capture code is never
re-entered.
This routine requires the following parameters in order to do its job:
This routine returns the following eror codes:
NO_ERROR if everything went well.
something else if there was an error. */
int monitor_the_keyboard()
{
USHORT error;
HMONITOR handle;
MONIN input[10];
MONOUT output[10];
SEL local, global, selector;
USHORT session;
PLINFOSEG ldt;
struct kbd_packet raw;
USHORT packet_size;
BYTE *new_stack;
TID id;
/* Get some data that we need in order to register
a monitor with the keyboard device driver. */
error = DosGetInfoSeg( &global, &local );
ldt = MAKEPLINFOSEG( local );
session = ldt -> sgCurrent;
input[0].cb = sizeof( input );
output[0].cb = sizeof( output );
packet_size = sizeof( raw );
error = DosMonOpen( "KBD$", &handle );
/* Register ourselves as a character monitor with the KEYBOARD. */
error = DosMonReg( handle,
( BYTE *)&input,
( BYTE *)&output,
DEFAULT,
session );
do
{
/* Read from the monitor chain. */
error = DosMonRead( ( BYTE *)&input,
DCWW_WAIT,
( BYTE *)&raw,
&packet_size );
/* Don't allow the <CONTROL><PrintScreen> character AND
don't allow the <CONTROL><END> character to go back
into the keyboard data stream. */
if( !(raw.c.fsState & CONTROL) || (raw.c.chScan != END_KEY)
&&
!(raw.c.fsState & CONTROL) || (raw.c.chScan != PRINT_SCREEN) )
{
/* Write the character back to the monitor chain. */
error = DosMonWrite( (BYTE *)&output,
( BYTE *)&raw,
packet_size );
}
else if( (raw.c.fsState & CONTROL)
&&
(raw.c.chScan == PRINT_SCREEN)
&&
( !capturing ) )
{
/* Set the flag that shows that we are currently
capturing the contents of the Physical Video Buffer */
capturing = TRUE;
/* Allocate the memory for a stack for a new thread. */
DosAllocSeg( STACK_SIZE,
&selector,
RESERVED );
new_stack = MAKEP( selector, 0 );
/* Mark the stack so we can trace stack useage. */
mark_stack( ( CHAR *)new_stack,
STACK_SIZE );
/* Capture the contents of the current PHYSICAL VIDEO BUFFER. */
DosCreateThread( capture_the_screen,
&id,
( new_stack + STACK_SIZE - 2 ) );
}
}while( !(raw.c.fsState & CONTROL)
||
(raw.c.chScan != END_KEY) );
/* Close the monitor when we are done with it. */
error = DosMonClose( handle );
return( error );
}