home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / Libraries / TransSkel / Auxiliary / SkelCmdPeriod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-02-20  |  1.4 KB  |  58 lines  |  [TEXT/KAHL]

  1. /*
  2.  * SkelCmdPeriod.c -- Figure out, in an internationally compatible way, whether
  3.  * an event is a command-period key event.
  4.  *
  5.  * See TN TE 23, International Cancelling, for the rationale on how this works.
  6.  */
  7.  
  8. # include    <Script.h>
  9.  
  10. # include    "TransSkel.h"
  11.  
  12.  
  13. # define    kMaskModifiers    0xfe00
  14. # define    kMaskVirtualKey    0x0000ff00
  15. # define    kMaskAscii1        0x00ff0000
  16. # define    kMaskAscii2        0x000000ff
  17. # define    period            '.'
  18.  
  19.  
  20. pascal Boolean
  21. SkelCmdPeriod (EventRecord *evt)
  22. {
  23. short    keyCode;
  24. long    virtualKey;
  25. long    keyCId;
  26. long    keyInfo;
  27. long    state;
  28. long    lowChar, highChar;
  29. Handle    hKCHR;
  30.  
  31.     if (evt->what == keyDown || evt->what == autoKey)
  32.     {
  33.         if (evt->modifiers & cmdKey)            /* cmd key is down */
  34.         {
  35.             /* find out ASCII equivalent for key */
  36.             virtualKey = (evt->message & kMaskVirtualKey) >> 8;
  37.             /* "and" out command key, "or" in the virtual key */
  38.             keyCode = (evt->modifiers & kMaskModifiers) | virtualKey;
  39.             keyCId = GetScript (GetEnvirons (smKeyScript), smScriptKeys);
  40.             hKCHR = GetResource ('KCHR', keyCId);
  41.             if (hKCHR != (Handle) nil)
  42.             {
  43.                 state = 0;
  44.                 /* don't bother locking because KeyTrans doesn't move memory */
  45.                 keyInfo = KeyTrans (*hKCHR, keyCode, &state);
  46.                 ReleaseResource (hKCHR);
  47.             }
  48.             else
  49.                 keyInfo = evt->message;
  50.  
  51.             lowChar = keyInfo & kMaskAscii2;
  52.             highChar = (keyInfo & kMaskAscii1) >> 16;
  53.             if (lowChar == period || highChar == period)
  54.                 return (true);
  55.         }
  56.     }
  57.     return (false);
  58. }