Kết hợp giữa lập trình hệ thống trong C để lấy các sự kiện chuột. Chương trình đơn giản nhưng cho chúng ta cách tiếp cận và sử lý các sự kiện chuột trong lập trình C

Code:

typedef struct R2 {
   int x,y;
};

void Getch() {
   asm {
      mov ah,1
      int 21h
   }
}
void InitGraph() {
   asm {
      mov ah,0
      mov al,12h
      int 10h
   }
}
void CloseGraph() {
   asm {
      mov ah,0
      mov al,2h
      int 10h
   }
}
void putpixel(int x, int y,unsigned char Color) {
   asm {
      mov ah,0ch
      mov dx,y
      mov cx,x
      mov al,Color
      mov bh,0
      int 10h
   }
}

void MouseReset() {
   asm {
      mov ax,0h
      int 33h
   }
}

void MouseShow() {
   asm {
      mov ah,0
      mov al,1
      int 33h
   }
}

void MouseHide() {
   asm {
      mov ah,0
      mov al,2
      int 33h
   }
}

char LeftMouseOnDown() {
      char k=0;
   asm {
         mov ah,0
         mov al,3
      int 33h
         and bx,0000000000000001b
         mov k,bl
      }
      return k;
   }

char RightMouseOnDown() {
      char k=0;
   asm {
         mov ah,0
         mov al,3
      int 33h
         shr bx,1
         and bx,0000000000000001b
      mov k,bl
      }
   return k;
}

R2 GetMousePostion() {
   R2 p;
   int x,y;
   asm {
         mov ah,3
         int 33h
      mov x,cx
         mov y,dx
   }
      p.x = x;
   p.y = y;
      return p;
}
void main() {
   InitGraph();
   MouseReset();
   MouseShow();
   R2 point;
   while(!RightMouseOnDown()) {
      point = GetMousePostion();
      if (LeftMouseOnDown()) {
         putpixel(point.x,point.y,14);
      }
   }
   CloseGraph();
   MouseHide();
}