我也发一个c语言实现 鼠标的功能
程序代码:
/* Note:Your choice is C IDE */ #include "stdio.h" #include "graphics.h" #include "dos.h" #include "math.h" int init(); void tu(); float x=20,y=240; int x1,y1; int n=1,old_n; int start=0; union REGS regs; void main() {int gr=DETECT,gm; initgraph(&gr,&gm,"c:\\jmsoft\\drv");\*这里要改成你编译器的位置*\ init_mouse(); while(!kbhit()) tu(); } void tu() {init(); setcolor(RED); mouse_read(); setcolor(RED); circle(x,y,24); switch(n) { case 1:old_n=1;line(x-12*sqrt(2),y-12*sqrt(2),x+12*sqrt(2),y+12*sqrt(2)); n=2;break; case 2:old_n=2;line(x,y-24,x,y+24);n=3;break; case 3:old_n=3;line(x+12*sqrt(2),y-12*sqrt(2),x-12*sqrt(2),y+12*sqrt(2)); n=4;break; case 4:old_n=4;line(x-24,y,x+24,y);n=1; break; } delay(10000); setcolor(BLACK); circle(x,y,24); switch(old_n) {case 1:line(x-12*sqrt(2),y-12*sqrt(2),x+12*sqrt(2),y+12*sqrt(2)); n=2;break; case 2:line(x,y-24,x,y+24);n=3;break; case 3:line(x+12*sqrt(2),y-12*sqrt(2),x-12*sqrt(2),y+12*sqrt(2)); n=4;break; case 4:line(x-24,y,x+24,y); break;} if(start==1&&x1<240&&x1>200&&y1>80&&y1<150) x+=3; } init() {int i,n; char str[20]="start"; srand(time(NULL)); n=rand()%6+1; setcolor(n); outtextxy(200,100,str); } int init_mouse() { regs.x.ax=0; int86(0x33,®s,®s); regs.x.ax=4; x1=regs.x.cx=320; y1=regs.x.dx=240; int86(0x33,®s,®s); setcolor(GREEN); circle(x1,y1,6); putpixel(x1,y1,RED); line(x1,y1+6,x1,y-6); line(x1-6,y1,x1+6,y); } int mouse_read() {delay(1000); regs.x.ax=3; int86(0x33,®s,®s); setcolor(BLACK); circle(x1,y1,6); putpixel(x1,y1,RED); line(x1,y1+6,x1,y1-6); line(x1-6,y1,x1+6,y1); delay(1000); x1=regs.x.cx; y1=regs.x.dx; if(regs.x.bx==1) if((x1>=1)) start=1; setcolor(BLUE); circle(x1,y1,6); putpixel(x1,y1,RED); line(x1,y1+6,x1,y1-6); line(x1-6,y1,x1+6,y1); }