Microsoft KB Archive/67861

Programming a Double-Click PSS ID Number: Q67861 Article last modified on 05-12-1993 PSS database name: H_Mouse

6.x 7.x 8.x 9.00

MS-DOS

Summary:

The action of double-clicking a mouse button must be caught and recognized by the program. It is the responsibility of the programmer to provide support for double-clicking.

More Information:

A double-click is defined as clicking a mouse button twice within a specified time frame. For the program to recognize a double-click, the programmer must keep track of the time between clicks. The Master Clock Count byte is a readily available source for timer information. It is located at 0040:006C and is a four-byte number. Mouse functions five and six are necessary to accomplish button press/release recognition.

The following C program illustrates the use of mouse functions five and six to recognize a double-click:


 * 1) include  #include  #include  #include 

union REGS iregs, oregs; struct SREGS segregs;

main { int LastClick, ThisClick; int DoubleClick; int far * MCC = (int far ) 0x0040006c; /Master Clock/ /Count / LastClick = MCC; DoubleClick = 0; /Init DblClk /

iregs.x.ax = 0;               /*Reset Mouse */ int86(0x33, &iregs, &oregs);

iregs.x.ax = 1;               /*Show Mouse  */ int86(0x33, &iregs, &oregs);

while (!kbhit) { if(DoubleClick) {                 /*If double-  */ iregs.x.ax = 4;               /*click, then */ iregs.x.dx = 0;               /*set cursor  */ iregs.x.cx = 0;               /*upper left  */ int86(0x33, &iregs, &oregs);  /*of screen. */

DoubleClick = 0;              /*Reset DblClk*/ } iregs.x.ax = 5;                   /*Check for   */ int86(0x33, &iregs, &oregs);      /*button press*/ if (oregs.x.bx > 0) {             /*If pressed, */ ThisClick = *MCC;             /*note count &*/ iregs.x.ax = 6;               /*wait for    */ int86(0x33, &iregs, &oregs);  /*release of  */ while (oregs.x.bx < 1) {      /*mouse button*/ iregs.x.ax = 6; int86(0x33, &iregs, &oregs); }    if ((ThisClick - LastClick) < 9)    /*There are*/ DoubleClick = 1;                  /*18.2 system */ /*timer ticks */ LastClick = ThisClick;             /*per second. */                         /*The value of*/ /*9 selects .5*/ /*sec. double */ /*click. */

} } iregs.x.ax = 0;               /*Reset mouse */ int86(0x33, &iregs, &oregs); }

Additional reference words: program C double click 8.00 8.10 8.20 9.00

Copyright Microsoft Corporation 1993.