home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / mac / source / cshowint.sit / CapsLockINIT.c next >
C/C++ Source or Header  |  1989-10-13  |  3KB  |  78 lines

  1. /*-------------------------------------------------------------------------
  2.     Filename:    CapsLockINIT.c
  3.     
  4.     Author:      Ken McLeod
  5.                       {zardoz,felix}!dhw68k!thecloud
  6.                       thecloud@dhw68k.cts.com
  7.  
  8.     This file is copyright ⌐1989 by its author.
  9.     Permission is granted to use and distribute this code freely.
  10.     
  11.     This example INIT checks to see if the Caps Lock key is down at startup,
  12.     and if so, loops until it is released. One purpose of this is to allow
  13.     time to examine (and explain to onlookers!) all the ShowINIT icons on
  14.     the screen. It's best to rename the INIT 'Zaps Lock' (or whatever) so
  15.     that it will be the last INIT to run.
  16.     
  17.     Note that CapsLockINIT is simply a "one-shot" piece of code; it doesn't
  18.     patch any traps or install itself into the System heap, since it has no
  19.     function after startup.
  20.     
  21.   1.0d1        2/9/89        - initial version
  22.   1.0b1        3/6/89        -    fixed error in second icon placement
  23.   1.0b2        3/27/89        -    fixed CQD bug in CShowINIT.c
  24.   1.0            4/5/89        -    converted CShowINIT.c to separate 'PROC' resource
  25.   1.01        10/10/89    - new ICN# & cicn; added continuous animation in loop
  26.                                           so unsuspecting users won't think the Mac has hung!
  27.   
  28.   -------------------------------------------------------------------------*/
  29.  
  30. /* #include <MacHeaders> */
  31.  
  32. #define    CAPSLOCK    62
  33. #define    BASE_ID        128
  34. #define    PROC_ID        128
  35.  
  36. caps_down()        /* test state of Caps Lock key */
  37. {
  38.     KeyMap    theKeyMap;
  39.  
  40.     GetKeys(&theKeyMap);
  41.     if (BitTst(&theKeyMap,CAPSLOCK))    return (1);
  42.     else    return (0);
  43. }
  44.  
  45. void    main()
  46. {
  47.     Handle    procHdl;    /* handle to our CShowINIT 'PROC' code resource */
  48.     short        which;        /* toggles icon to be drawn in animation loop */
  49.     long        oldtix;        /* saved tick count for animation */
  50.     long        tix;            /* current tick count */
  51.  
  52.     oldtix = TickCount();        /* init saved ticks */
  53.     which    = 1;                            /* init icon counter to "key is down" */
  54.  
  55.     /* load the CShowINIT 'PROC' resource and lock it down */
  56.     if ((procHdl = GetResource('PROC', PROC_ID)) != 0L)    {
  57.         HLock(procHdl);
  58.  
  59.         while (caps_down())    {
  60.             tix = TickCount();
  61.             if (tix > oldtix+16) {
  62.                 /* call CShowINIT with iconID and moveX arguments */
  63.                 /* last argument is a pointer to the function entry point */
  64.                 CallPascal(BASE_ID + which, 0, *procHdl);
  65.                 oldtix = tix;
  66.                 which = !which;        /* toggle between the 2 icons */
  67.             }
  68.         }
  69.         /* we've fallen out of the loop (if we were ever in it) */
  70.         CallPascal(BASE_ID, -1, *procHdl);    /* draw "key is up" icon */
  71.  
  72.         HUnlock(procHdl);
  73.     }
  74.     else    SysBeep(10);    /* couldn't find our 'PROC' resource! */
  75. }
  76.  
  77. /*-------------------------------------------------------------------------*/
  78.