Logo 
Search:

C Programming Articles

Submit Article
Home » Articles » C Programming » Mouse ProgrammingRSS Feeds

Program to show the Basic Mouse Handling in Text Mode

Posted By: Easy Tutor     Category: C Programming     Views: 3931

Write a program to show the Basic Mouse Handling in Text Mode.

Code for Program to show the Basic Mouse Handling in Text Mode in C Programming

 # include <stdio.h>
 # include <conio.h>
 # include   <dos.h>

 constint InitMouse( );

 void ShowMouseCursor( );
 void HideMouseCursor( );

 void SetMousePosition(int x,int y);
 void GetMousePosition(int *x,int *y);

 void SetMouseHorizontalRange(int x_min,int x_max);
 void SetMouseVerticalRange(int y_min,int y_max);
 void SetMouseRange(int x_min,int y_min,int x_max,int y_max);

 constint LeftMouseKeyPressed( );
 constint RightMouseKeyPressed( );

 void show_border( );

 int main( )
 {
    int x_cord;
    int y_cord;

    int prev_x_cord;
    int prev_y_cord;

    clrscr( );
    textmode(BW80);

    if(!InitMouse( ))
    {
       printf("Fatal Error : Unable to detect the Mouse.");
       printf("\nPress ANY key to exit...");

       getch( );
       exit(1);
    }

    show_border( );

    ShowMouseCursor( );
    SetMousePosition(320,100);
    SetMouseRange(16,24,623,183);

    gotoxy(1,25);
    printf("Note: Press ANY key to exit.");

    do
    {
       GetMousePosition(&x_cord,&y_cord);

       if(x_cord!=prev_x_cord || y_cord!=prev_y_cord)
       {
      gotoxy(1,1);
      printf("Current Mouse Coordinates : ( x=%u , y=%u ) ",x_cord,y_cord);

      prev_x_cord=x_cord;
      prev_y_cord=y_cord;
       }

       if(LeftMouseKeyPressed( ))
       {
      gotoxy(1,2);
      printf("*** Left Mouse Key Pressed");

      while(LeftMouseKeyPressed( ));

      gotoxy(1,2);
      printf("                           ");
       }

       if(RightMouseKeyPressed( ))
       {
      gotoxy(1,2);
      printf("*** Right Mouse Key Pressed");

      while(RightMouseKeyPressed( ));

      gotoxy(1,2);
      printf("                           ");
       }
    }
    while(!kbhit( ));

    getch( );
    return 0;
 }

 /*************************************************************************///--------------------------  show_border( )  ---------------------------///*************************************************************************/void show_border( )
 {
    int i;

    gotoxy(2,3);
    printf("ÉÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»");

    for(i=0;i<20;i++)
    {
       gotoxy(2,(4+i));
       printf("º                                                                            º");
    }

    gotoxy(2,24);
    printf("ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ");
 }

 /*************************************************************************///---------------------------  InitMouse( )  ----------------------------///*************************************************************************/constint InitMouse( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0000;

    int86(0x33,&InReg,&OutReg);

    if(OutReg.x.ax==0x0000 && OutReg.x.bx==0xFFFF)
       return 0;

    return 1;
 }

 /*************************************************************************///-------------------------  ShowMouseCursor( )  ------------------------///*************************************************************************/void ShowMouseCursor( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0001;

    int86(0x33,&InReg,&OutReg);
 }

 /*************************************************************************///-------------------------  HideMouseCursor( )  ------------------------///*************************************************************************/void HideMouseCursor( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0002;

    int86(0x33,&InReg,&OutReg);
 }

 /*************************************************************************///------------------------  SetMousePosition( )  ------------------------///*************************************************************************/void SetMousePosition(int x,int y)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0004;
    InReg.x.cx=x;
    InReg.x.dx=y;

    int86(0x33,&InReg,&OutReg);
 }

 /*************************************************************************///-------------------------  GetMousePosition( )  -----------------------///*************************************************************************/void GetMousePosition(int *x,int *y)
 {
    union REGS InReg;
    union REGS OutReg;

    *x=0;
    *y=0;

    InReg.x.ax=0x0003;

    int86(0x33,&InReg,&OutReg);

    *x=OutReg.x.cx;
    *y=OutReg.x.dx;
 }

 /*************************************************************************///----------------------  SetMouseHorizontalRange( )  -------------------///*************************************************************************/void SetMouseHorizontalRange(int x_min,int x_max)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0007;
    InReg.x.cx=x_min;
    InReg.x.dx=x_max;

    int86(0x33,&InReg,&OutReg);
 }

 /*************************************************************************///----------------------  SetMouseVerticalRange( )  ---------------------///*************************************************************************/void SetMouseVerticalRange(int y_min,int y_max)
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0008;
    InReg.x.cx=y_min;
    InReg.x.dx=y_max;

    int86(0x33,&InReg,&OutReg);
 }

 /*************************************************************************///--------------------------  SetMouseRange( )  -------------------------///*************************************************************************/void SetMouseRange(int x_min,int y_min,int x_max,int y_max)
 {
    SetMouseVerticalRange(y_min,y_max);
    SetMouseHorizontalRange(x_min,x_max);
 }

 /*************************************************************************///----------------------  LeftMouseKeyPressed( )  -----------------------///*************************************************************************/constint LeftMouseKeyPressed( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0003;

    int86(0x33,&InReg,&OutReg);

    return ((OutReg.x.bx==0x0001)?1:0);
 }

 /*************************************************************************///----------------------  RightMouseKeyPressed( )  ----------------------///*************************************************************************/constint RightMouseKeyPressed( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.x.ax=0x0003;

    int86(0x33,&InReg,&OutReg);

    return ((OutReg.x.bx==0x0002)?1:0);
 }
  
Share: 


Didn't find what you were looking for? Find more on Program to show the Basic Mouse Handling in Text Mode Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to show the Basic Mouse Handling in Text Mode is from United States. Easy Tutor says

Hello Friends,

I am Free Lance Tutor, who helped student in completing their homework.

I have 4 Years of hands on experience on helping student in completing their homework. I also guide them in doing their final year projects.

I have share many programs on this website for everyone to use freely, if you need further assistance, than please contact me on easytutor.2ya [at the rate] gmail [dot] com

I have special discount scheme for providing tutor services. I am providing tutor service to students from various contries, currently most of my students are from United States, India, Australia, Pakistan, Germany, UK and Canada.

I am also here to expand my technical network to receive more opportunity in my career, make friends to help them in resolving their technical problem, learn and share my knowledge, If you like to be my friend, Please send me friend request.

Thanks,
Happy Programming :)

 
View All Articles

 
Please enter your Comment

  • Comment should be atleast 30 Characters.
  • Please put code inside [Code] your code [/Code].

 
No Comment Found, Be the First to post comment!