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;

InitMouse()
{
i.x.ax=0;
int86 (0x33,&i,&o);
return(o.x.ax);
}

void ShowMousePointer()
{
i.x.ax=1;
int86 (0x33,&i,&o);
}

void GetPositionAndButton(int *button, int *x, int *y)
{
i.x.ax=3;
int86 (0x33,&i,&o);
*button=o.x.bx;
*x=o.x.cx;
*y=o.x.dx;
}

void HideMousePointer()
{
i.x.ax=2;
int86 (0x33,&i,&o);
}

Usage:
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 🙂

Advertisements

2 Responses to “Mouse Interaction using C/C++”

  1. Mouse Says:

    Computermouse

    yeah thats what I ment, i didnt remember the spelling but i did remember the meaning of the Mouse

  2. A3 Says:

    Thanks so much
    u saved my life man
    thanks again


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: