Mouse Interaction using C/C++

Hi everyone…

Following is the headerfile contains functions to interact with mouse. I took the hint from “Let Us C”.

#include <dos.h>

union REGS i,o;

int86 (0x33,&i,&o);

void ShowMousePointer()
int86 (0x33,&i,&o);

void GetPositionAndButton(int *button, int *x, int *y)
int86 (0x33,&i,&o);

void HideMousePointer()
int86 (0x33,&i,&o);

1. call the InitMouse() function to initialize. (Once required)
2. Call the function ShowMousePointer() to make the pointer appear in your application.
3. The function GetPositionAndButton will return the current mouse pointer location in terms of x & y coordinate and the button status, i.e., left or right etc..
4. You can hide your mouse pointer by calling HideMousePointer function.

Now you can capture the mouse activities using following loop.

while (!kbhit())
getmousepos (&button,&x,&y);
gotoxy (5,3);
(button &1)== 1 ? printf (“Left Down”): printf (“Left UP”);
gotoxy (20,3);
(button &2 )==2 ? printf (“Rigt Down”): printf (“Right UP”);
gotoxy (1,1);
printf (“x = %3d, y = %3d”,x,y);

5. Thats it.

Keep Smiling 🙂