home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Garbo
/
Garbo.cdr
/
mac
/
source
/
cshowint.sit
/
CapsLockINIT.c
next >
Wrap
C/C++ Source or Header
|
1989-10-13
|
3KB
|
78 lines
/*-------------------------------------------------------------------------
Filename: CapsLockINIT.c
Author: Ken McLeod
{zardoz,felix}!dhw68k!thecloud
thecloud@dhw68k.cts.com
This file is copyright ⌐1989 by its author.
Permission is granted to use and distribute this code freely.
This example INIT checks to see if the Caps Lock key is down at startup,
and if so, loops until it is released. One purpose of this is to allow
time to examine (and explain to onlookers!) all the ShowINIT icons on
the screen. It's best to rename the INIT 'Zaps Lock' (or whatever) so
that it will be the last INIT to run.
Note that CapsLockINIT is simply a "one-shot" piece of code; it doesn't
patch any traps or install itself into the System heap, since it has no
function after startup.
1.0d1 2/9/89 - initial version
1.0b1 3/6/89 - fixed error in second icon placement
1.0b2 3/27/89 - fixed CQD bug in CShowINIT.c
1.0 4/5/89 - converted CShowINIT.c to separate 'PROC' resource
1.01 10/10/89 - new ICN# & cicn; added continuous animation in loop
so unsuspecting users won't think the Mac has hung!
-------------------------------------------------------------------------*/
/* #include <MacHeaders> */
#define CAPSLOCK 62
#define BASE_ID 128
#define PROC_ID 128
caps_down() /* test state of Caps Lock key */
{
KeyMap theKeyMap;
GetKeys(&theKeyMap);
if (BitTst(&theKeyMap,CAPSLOCK)) return (1);
else return (0);
}
void main()
{
Handle procHdl; /* handle to our CShowINIT 'PROC' code resource */
short which; /* toggles icon to be drawn in animation loop */
long oldtix; /* saved tick count for animation */
long tix; /* current tick count */
oldtix = TickCount(); /* init saved ticks */
which = 1; /* init icon counter to "key is down" */
/* load the CShowINIT 'PROC' resource and lock it down */
if ((procHdl = GetResource('PROC', PROC_ID)) != 0L) {
HLock(procHdl);
while (caps_down()) {
tix = TickCount();
if (tix > oldtix+16) {
/* call CShowINIT with iconID and moveX arguments */
/* last argument is a pointer to the function entry point */
CallPascal(BASE_ID + which, 0, *procHdl);
oldtix = tix;
which = !which; /* toggle between the 2 icons */
}
}
/* we've fallen out of the loop (if we were ever in it) */
CallPascal(BASE_ID, -1, *procHdl); /* draw "key is up" icon */
HUnlock(procHdl);
}
else SysBeep(10); /* couldn't find our 'PROC' resource! */
}
/*-------------------------------------------------------------------------*/