Logo 
Search:

C Programming Articles

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

Program to show the implementation of Double Mouse Click

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

Write a program to show the implementation of Double Mouse Click.

Code for Program to show the implementation of Double Mouse Click in C Programming

 # include <stdlib.h>
 # 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( );

 constint DoubleLeftMouseKeyPressed( );
 constint DoubleRightMouseKeyPressed( );

 constint GetClickTime( );

 void ShowSystemTime( );

 void ShowBorder( );

 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);
    }

    ShowBorder( );

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

    gotoxy(1,25);
    printf("Note: Press Double Mouse Key to exit.");

    do
    {
       ShowSystemTime( );
       GetMousePosition(&x_cord,&y_cord);

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

      prev_x_cord=x_cord;
      prev_y_cord=y_cord;
       }

       if(DoubleLeftMouseKeyPressed( ))
      break;

       elseif(DoubleRightMouseKeyPressed( ))
      break;

       if(kbhit( ))
      getch( );
    }
    while(1);

    return 0;
 }

 /*************************************************************************///---------------------------  ShowBorder( )  ---------------------------///*************************************************************************/void ShowBorder( )
 {
    int count;

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

    for(count=0;count<20;count++)
    {
       gotoxy(2,(4+count));
       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);
 }

 /*************************************************************************///-------------------  DoubleLeftMouseKeyPressed( )  --------------------///*************************************************************************/constint DoubleLeftMouseKeyPressed( )
 {
    long first_click_time=0;
    long second_click_time=0;

    if(LeftMouseKeyPressed( ))
    {
       first_click_time=GetClickTime( );

       while(LeftMouseKeyPressed( ));

       do
       {
      second_click_time=GetClickTime( );
      second_click_time+=((GetClickTime( )<first_click_time)?100:0);

      if(LeftMouseKeyPressed( ))
      {
         while(LeftMouseKeyPressed( ));

         return 1;
      }
       }
       while((second_click_time-first_click_time)<25);
    }

    return 0;
 }

 /*************************************************************************///-------------------  DoubleRightMouseKeyPressed( )  -------------------///*************************************************************************/constint DoubleRightMouseKeyPressed( )
 {
    long first_click_time=0;
    long second_click_time=0;

    if(RightMouseKeyPressed( ))
    {
       first_click_time=GetClickTime( );

       while(RightMouseKeyPressed( ));

       do
       {
      second_click_time=GetClickTime( );
      second_click_time+=((GetClickTime( )<first_click_time)?100:0);

      if(RightMouseKeyPressed( ))
      {
         while(RightMouseKeyPressed( ));

         return 1;
      }
       }
       while((second_click_time-first_click_time)<25);
    }

    return 0;
 }

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

    InReg.h.ah=0x2C;

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

    return OutReg.h.dl;
 }

 /*************************************************************************///-------------------------  ShowSystemTime( )  -------------------------///*************************************************************************/int prev_hr=0;
 int prev_min=0;
 int prev_sec=0;

 void ShowSystemTime( )
 {
    union REGS InReg;
    union REGS OutReg;

    InReg.h.ah=0x2C;

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

    if(prev_hr!=(int)OutReg.h.ch || prev_min!=(int)OutReg.h.cl ||
                         prev_sec!=(int)OutReg.h.dh)
    {
       gotoxy(67,2);
       printf("             ");

       gotoxy(67,2);

       if((int)OutReg.h.ch>9)
      printf("%d",(int)OutReg.h.ch);

       else
      printf("0%d",(int)OutReg.h.ch);

       printf(" : ");

       if((int)OutReg.h.cl>9)
      printf("%d",(int)OutReg.h.cl);

       else
      printf("0%d",(int)OutReg.h.cl);

       printf(" : ");

       if((int)OutReg.h.dh>9)
      printf("%d",(int)OutReg.h.dh);

       else
      printf("0%d",(int)OutReg.h.dh);

       prev_hr=(int)OutReg.h.ch;
       prev_min=(int)OutReg.h.cl;
       prev_sec=(int)OutReg.h.dh;
    }
 }
  
Share: 


Didn't find what you were looking for? Find more on Program to show the implementation of Double Mouse Click Or get search suggestion and latest updates.

Easy Tutor
Easy Tutor author of Program to show the implementation of Double Mouse Click 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

Related Articles and Code:


 
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!