// C program to determine the current
// mouse position and button clicked
#include <conio.h>
#include <dos.h>
#include <graphics.h>
#include <stdio.h>
union REGS in, out;
// Function to initialize the mouse
// pointer using graphics
int initMouse()
{
in.x.ax = 0;
int86(0X33, &in, &out);
return out.x.ax;
}
// Function to display the mouse
// pointer using graphics
void showMouse()
{
in.x.ax = 1;
int86(0X33, &in, &out);
}
// Function to get the current clicked
// mouse position on the screen
void getMousePosition(int* click,
int* x, int* y)
{
in.x.ax = 3;
int86(0X33, &in, &out);
// Get the coordinates
*click = out.x.bx;
// Update the x and y coordinates
*x = out.x.cx;
*y = out.x.dx;
}
// Driver Code
void main()
{
int status, i, gd = DETECT, gm;
// Initialize graphics
initgraph(&gd, &gm, "C:\\TURBOC3\\BGI");
// Get the status of the mouse
status = initMouse();
// Check if mouse is available or not
if (status == 0)
printf("Mouse support "
"not available.\n");
else {
showMouse();
// Get the current mouse position
getMousePosition(&click, &x, &y);
while (!kbhit()) {
getMousePosition(&click, &x, &y);
gotoxy(1, 1);
printf("X = %d, Y = %d", x, y);
if (click == 1)
printf("\nLeft click at "
"position = %d, %d\t",
x, y);
if (click == 2)
printf("\nRight click at "
"position = %d, %d\t",
x, y);
}
}
getch();
// Close the graphics
closegraph();
}