Hi friends,
Here I am describing the implementation of mouse in Turbo c compiler.
Turbo c is an old c compiler works based on Dos operating System.It works
in the text mode.But have little graphical functions.
Now Turbo C is not using widely,because of it's poor graphical performance and
dos based working.But for students who learn c programming Turbo c is the better choice.
Here is a sample program which implement mouse and handle it well.
int86() is the core function using to implement mouse.It is defined in header file 'dos.h'.
#include<conio.h>
#include<mouse.h>
#include<stdio.h>
union REGS in,out;
void restrictmouse()
{
in.x.ax=7;
in.x.cx=0;
in.x.dx=639;
int86(0x33,&in,&out);
in.x.ax=8;
in.x.cx=0;
in.x.dx=479;
int86(0x33,&in,&out);
}
void showmouse()
{
in.x.ax=1;
int86(0x33,&in,&out);
}
void main()
{
restrictmouse();
do
{
showmouse();
in.x.ax=3;
int86(0x33,&in,&out);
if(out.x.bx==1)
printf("Left button clicked");
if(out.x.bx==2)
printf("Right button clicked");
if(out.x.bx==3)
printf("Middle button clicked");
}while(!kbhit());
}
REGS is an union predefined in Turbo c library.We declare two variables
of REGS type.It defines so many member variables.
x.ax defines which opration to be done by mouse.
For instance if in.x.ax=1 and call int86(0x33,&in,&out) the meanig is
show mouse pointer.
if in.x.ax=0 Detect mouse
in.x.ax=2 Show mouse video
in.x.ax=3 Get x and y cordinates of mouse pointer and button clicked in out.
That is x=out.x.cx
y=out.x.dx
Button clicked is : out.x.bx
if in.x.ax=4 it mean hide mouse
7&8 for restrict mouse pointer,Restric mouse is means that define the
area in which the mouse pointer will be displayed.
7 is for restrict in x direction and 8 for y direction.
in.x.ax=7;
in.x.cx=x1;
in.x.dx=x2;
in.x.ax=8;
in.x.cx=y1;
in.x.dx=y2;
in.x.ax=7;
in.x.cx=0;
in.x.dx=639;
will restrict the mouse to all 640 pixels in x direction.
in.x.ax=8
in.x.cx=0;
in.x.dx=479;
will restrict the mouse to all 480 pixels in y direction.
Hope that this post will be helpful to you.Continue reading, the coming
post will be more helpful. Thanks by Sukesh B R
Here I am describing the implementation of mouse in Turbo c compiler.
Turbo c is an old c compiler works based on Dos operating System.It works
in the text mode.But have little graphical functions.
Now Turbo C is not using widely,because of it's poor graphical performance and
dos based working.But for students who learn c programming Turbo c is the better choice.
Here is a sample program which implement mouse and handle it well.
int86() is the core function using to implement mouse.It is defined in header file 'dos.h'.
#include<conio.h>
#include<mouse.h>
#include<stdio.h>
union REGS in,out;
void restrictmouse()
{
in.x.ax=7;
in.x.cx=0;
in.x.dx=639;
int86(0x33,&in,&out);
in.x.ax=8;
in.x.cx=0;
in.x.dx=479;
int86(0x33,&in,&out);
}
void showmouse()
{
in.x.ax=1;
int86(0x33,&in,&out);
}
void main()
{
restrictmouse();
do
{
showmouse();
in.x.ax=3;
int86(0x33,&in,&out);
if(out.x.bx==1)
printf("Left button clicked");
if(out.x.bx==2)
printf("Right button clicked");
if(out.x.bx==3)
printf("Middle button clicked");
}while(!kbhit());
}
REGS is an union predefined in Turbo c library.We declare two variables
of REGS type.It defines so many member variables.
x.ax defines which opration to be done by mouse.
For instance if in.x.ax=1 and call int86(0x33,&in,&out) the meanig is
show mouse pointer.
if in.x.ax=0 Detect mouse
in.x.ax=2 Show mouse video
in.x.ax=3 Get x and y cordinates of mouse pointer and button clicked in out.
That is x=out.x.cx
y=out.x.dx
Button clicked is : out.x.bx
if in.x.ax=4 it mean hide mouse
7&8 for restrict mouse pointer,Restric mouse is means that define the
area in which the mouse pointer will be displayed.
7 is for restrict in x direction and 8 for y direction.
in.x.ax=7;
in.x.cx=x1;
in.x.dx=x2;
in.x.ax=8;
in.x.cx=y1;
in.x.dx=y2;
in.x.ax=7;
in.x.cx=0;
in.x.dx=639;
will restrict the mouse to all 640 pixels in x direction.
in.x.ax=8
in.x.cx=0;
in.x.dx=479;
will restrict the mouse to all 480 pixels in y direction.
Hope that this post will be helpful to you.Continue reading, the coming
post will be more helpful. Thanks by Sukesh B R