ecollins@nmsu.edu (Edward Collins) (12/31/90)
Hello, Would someone please pass along an example of how to setup and use mouse function 12 ( define event handler ) or point out what's wrong with the test pgm below? I'm curious why this function (12) seems to be neglected in all the books I've looked in. It seems like the most useful of all the functions in the mouse driver, after all why would we want to do any polling if we don't have to. Does anyone know of a good reason not to use mouse function 12? Do most people simply poll for mouse events? Please respond via e-mail. I'll summarize if there's enough interest. Thanks in advance. Mike. ecollins@nmsu.edu --- This minimal test program is self contained, except for a BGI driver which is assumed to be in the current directory. /* **============================================================================ ** mtest() -- ** ** Turbo C/C++ test program for ms mouse function 12 (set event handler). ** ** Executes fine, but handler is not entered. ** ** Assumes a proper BGI driver in current directory, ie EGAVGA.BGI. ** **============================================================================ */ #include <dos.h> #include <stdio.h> #include <graphics.h> void Handler( void ); void SetEventHandler( int Mask, void far (*handler)( void ) ); void DetectMouse( int *MouseStatus, int *NumberOfButtons ); void ShowCursor( void ); union REGS regs; struct SREGS sregs; int main() { int graphdriver = DETECT; int graphmode; int MouseStatus, NumberOfButtons; initgraph( &graphdriver, &graphmode, "" ); DetectMouse( &MouseStatus, &NumberOfButtons ); if ( !MouseStatus ) { closegraph(); printf( "No mouse was detected\n" ); return 0; } ShowCursor(); SetEventHandler( 0xff, (void far (*) (void)) (Handler) ); while ( !kbhit() ); closegraph(); return 0; } /*===========================================================================*/ void Handler() { printf( "In event handler\n" ); } /*===========================================================================*/ void DetectMouse( int *MouseStatus, int *NumberOfButtons ) { regs.x.ax = 0; int86( 51, ®s, ®s ); *MouseStatus = regs.x.ax; *NumberOfButtons = regs.x.bx; } /*===========================================================================*/ void ShowCursor( void ) { regs.x.ax = 1; int86( 51, ®s, ®s ); } /* **============================================================================= ** SetEventHandler() -- ** ** Function 12 defines the address entry location of an event handler routine ** which is called when a certain event (defined by the call mask) occurs. ** The program is temporarily interrupted by the mouse driver. At the end of ** the event handler routine the program continues at the point it was ** interrupted. ** ** The call mask is a single integer value defining the conditions which will ** cause an interrupt. ** ** A specific condition corresponds to a bit in the call mask: ** ** Mask Bit Condition ** -------------------------------------------------- ** 0 cursor location changed ** 1 left button pressed ** 2 left button released ** 3 right button pressed ** 4 right button released ** 5 middle button pressed ** 6 middle button released ** 7 - 15 not used ** ** To enable the event handler routine, set the mask bit to non-zero, to ** disable it set it to zero and make a call to this function. ** Always be sure to set the call mask to 0 before the program finishes. ** (Leave the system in the same state upon exit as if was upon entrance.) ** ** Input: AX = 12 ** CX = call mask ** ES:DX = pointer to event handler routine ** Return: none ** **============================================================================= */ void SetEventHandler( int Mask, void far (*handler)( void ) ) { regs.x.ax = 12; regs.x.cx = Mask; regs.x.dx = FP_OFF( handler ); sregs.es = FP_SEG( handler ); int86x( 51, ®s, ®s, &sregs ); } -- =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-= = Mike Collins | "Why would I want to change my = = New Mexico State University | mind? Is there something wrong = = e-mail: ecollins@nmsu.edu | with the one I have?" -- Spock = =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
routley@tle.enet.dec.com (01/03/91)
>Would someone please pass along an example of how to setup and use mouse >function 12 ( define event handler ) or point out what's wrong with the >test pgm below? Try declaring handler() to be void far handler(). It might also be necessary to declare your set handler routine to be seteventhandler( eventmask, offset( handler), segment( offset)). I don't know why function 12 isn't emphasized more either. It may have something to do with the fact that the typical mechanism for passing information back to the main program from the handler ( using the PSP area) only works in Small and Compact memory models (CS of the handler is the same as the main program). The other possibility is that most programs also have to poll the keyboard, so its easy enough to poll the mouse in the process. Any other suggestions out there? Kevin
rein@fwi.uva.nl (Rein van den Boomgaard) (01/15/91)
> woulduld someone please pass along an example of how to setup and use mouse >function 12 ( define event handler ) or point out what's wrong with the >test pgm below? I have got some code which enables to use this function (define my own interrupt driven mouse handler) and I vaguely remember some tricks were needed. Please send me a mail If you want to have the code rein van den boomgaard rein@fwi.uva.nl -- Rein van den Boomgaard