קוד:
#include <graphics.h>
#include <dos.h>
#include <stdio.h>
#include <conio.h>
#include <time.h>
void showMouse(union REGS i, union REGS o)
{
i.x.ax=1;
int86(0x33,&i,&o);
}
void checkMouse(union REGS i, union REGS o)
{
i.x.ax=0;
int86(0x33,&i,&o);
}
void buttonPressed(union REGS i, union REGS o, int *button, int *x, int *y)
{
i.x.ax=3;
int86(0x33,&i,&o);
*button=o.x.bx&7;
*x=o.x.cx;
*y=o.x.dx;
}
void hideMouse(union REGS i, union REGS o)
{
i.x.ax=2;
int86(0x33,&i,&o);
}
main()
{
int gd=DETECT,gm;
union REGS i,o;
int button=0, x1, y1, x2, y2;
clock_t time_start, time_end;
FILE *f;
initgraph(&gd,&gm,""); //switch to graphic mode
checkMouse(i,o); //check if mouse is available
while(!kbhit())
{
showMouse(i,o); //show the mouse
time_start=clock(); //start stoper
buttonPressed(i,o,&button,&x1,&y1); //check what button was pressed and the co-ordinates of the mouse
x2=x1;
y2=y1;
time_end=clock(); //end stoper
while(button==1) //left button was pressed
{
/*** write the information to file ***/
f=fopen("DRAWING.txt","a");
fprintf(f, "%d %d %d %d %.1f\n", x1,y1,
x2,y2,(time_end-time_start)/CLK_TCK );
fclose(f);
hideMouse(i,o); //hide the mouse
line(x1,y1,x2,y2);
time_start=clock();
x1=x2;
y1=y2;
buttonPressed(i,o,&button,&x2,&y2);
if(button==1)
time_end=clock();
/*** write the information to file ***/
f=fopen("Drawing","a");
fprintf(f, "%d %d %d %d %.1f\n", x1,y1,
x2,y2,(time_end-time_start)/CLK_TCK );
fclose(f);
}
}
getch();
restorecrtmode();
}