home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 21
/
macformat_21.iso
/
Shareware
/
Programación
/
VideoToolbox
/
VideoToolboxSources
/
GetClicks.c
< prev
next >
Wrap
Text File
|
1996-06-07
|
2KB
|
62 lines
/*
GetClicks.c
waits for a mouse click, and then counts clicks (e.g. double-click, triple-click). Each
click must arrive within the acceptable double-click time of the previous,
as set in the Control Panel. Returns the number of clicks, 1 or more.
Aborts if the user hits Command-period.
Calls SndStop1() immediately after the first click on the assumption that the user is
responding to the sound and should get the feedback of knowing that the computer knows
s/he's now responding. SndStop1() is innocuous if in fact no sound is playing.
HISTORY:
4/30/88 dgp wrote it
3/31/90 dgp cleaned up code and documentation.
8/24/91 dgp Made compatible with THINK C 5.0.
3/30/91 dgp use SndStop1() instead of obsolete Sound Driver.
1/25/93 dgp removed obsolete support for THINK C 4.
4/29/95 dgp added GetNextEventOrQuit(), so that we can abort at any time by hitting Command-.
6/18/95 dgp changed abort() to exit(1) for better compatibility with CW atexit().
6/6/96 dgp replaced US-only test by IsCmdPeriod() test, which will work internationally.
6/7/96 dhb use PrintfExit so it will work in a MEX file.
dhb Fixed GetNextEventOrQuit so it compiles. It referenced an undefined variable.
*/
#include "VideoToolbox.h"
short GetClicks(void)
{
long ticks;
EventRecord event;
short clicks;
clicks=0;
while(!GetNextEventOrQuit(mDownMask,&event)) ;
SndStop1(); /* Stop sound on first click */
clicks++;
ticks=TickCount()+GetDblTime();
while(!GetNextEventOrQuit(mUpMask,&event)) ;
while(TickCount() < ticks) /* wait as long a possible for another click */
if(GetNextEventOrQuit(mDownMask,&event)){
clicks++;
ticks=TickCount()+GetDblTime();
while(!GetNextEventOrQuit(mUpMask,&event)) ;
}
return clicks;
}
short GetNextEventOrQuit(int mask,EventRecord *eventPtr)
{
if(GetNextEvent(mask|keyDownMask,eventPtr))switch(eventPtr->what){
case keyDown:
if(IsCmdPeriod(eventPtr)){
#if MATLAB
PrintfExit("GetClicks: User typed cmd-. EXITING.");
#else
PrintfExit("\nGetClicks: User typed cmd-. EXITING.\n");
#endif
}
return (mask&keyDownMask)!=0;
default:
return 1;
}else return 0;
}