home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / VideoToolbox 95.04.18 / VideoToolboxSources / IsCmdPeriod.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-15  |  3.2 KB  |  88 lines  |  [TEXT/MMCC]

  1. /*
  2. IsCmdPeriod.c
  3. You pass it an event record and it tells you whether or not the user has hit
  4. command-period (i.e. "cancel"). The straightforward way breaks on some non-US
  5. Systems because the keys get remapped (i.e. period!='.'). The elaborate way is
  6. supposed to work on all Systems, but hasn't been tested.
  7.  
  8. WARNING:
  9. This hasn't been tested. I haven't read the Script Manager chapter. The caching
  10. scheme (saving "period") might fail if you change script systems between calls
  11. to IsCmdPeriod.
  12.  
  13. dgp.
  14.  
  15. Copied from comp.sys.mac.programming:
  16.  
  17. From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
  18. Date: 13 May 93 19:41:38 GMT
  19. Organization: Kalamazoo College
  20.  
  21. >PLEASE everybody read the "International Canceling" tech note (in
  22. >"Text"), or in the official jargon: M.TE.InternationalCancel (yech).
  23. >
  24. >It explains that Command key combinations with non-letter keys may
  25. >map to Command-Shift key codes on international keyboards. And we
  26. >all know that Command-Shift gets intercepted by the operating system.
  27. >This is a pain, because it means you won't be able to cancel operations,
  28. >or have access to similar keyboard shortcuts.
  29.  
  30. Here's the function I use.  I think I took it pretty much straight from
  31. the TN, but I might have made some minor improvement, I don't recall
  32. what.  Anyway, maybe this'll save someone a few minutes' worth of
  33. typing:
  34. - -- 
  35.  Jamie McCarthy     Internet: k044477@kzoo.edu    AppleLink: j.mccarthy
  36.  
  37. HISTORY:
  38. 13 May 93 Jamie McCarthy posted it on comp.sys.mac.programming
  39. 6/23/93    dgp corrected bug of using "=" instead of "==" in an if statement.
  40.     Check for valid handle before dereferencing. Tightened up code a bit.
  41.     Not tested. 
  42. 6/30/93    dgp The elaborate method required for international systems seems
  43. excessive for routine use, so I added a shortcut. We go through the whole 
  44. rigamarole once, and note what the Cmd-period key presses were translated to.
  45. On subsequent occasions we just (quickly) check for that. 
  46. */
  47. #include "VideoToolbox.h" 
  48. #include <Types.h>
  49. #include <Script.h>
  50.  
  51. Boolean IsCmdPeriod(register EventRecord *event)
  52. {
  53.     static char period=0;    // what cmd-period gets mapped to.
  54.  
  55.     if(period) return (event->what == keyDown || event->what == autoKey)
  56.         && (event->modifiers & cmdKey)
  57.         && (event->message & charCodeMask) == period;
  58.     else{
  59.         Boolean isCmdPeriod=FALSE;
  60.         short keyCode;
  61.         long keyInfo,state,keyCID;
  62.         Handle hKCHR;
  63.         Ptr pKCHR;
  64.         
  65.         if ((event->modifiers & cmdKey)
  66.             && (event->what == keyDown || event->what == autoKey)){
  67.             pKCHR=(Ptr)GetEnvirons(smKCHRCache);    // returns NULL under System 6
  68.             if(pKCHR == NULL){
  69.                 keyCID=GetScript(GetEnvirons(smKeyScript),smScriptKeys);
  70.                 hKCHR=GetResource('KCHR',keyCID);
  71.                 if(hKCHR!=NULL)pKCHR=*hKCHR;
  72.             }else hKCHR=NULL;
  73.             if(pKCHR != NULL){
  74.                 // re-translate the virtual key to a char, without the command modifier
  75.                 keyCode=(event->message & keyCodeMask) >> 8;    // the virtual key
  76.                 keyCode |= event->modifiers & 0xFF00 & ~cmdKey;
  77.                 state=0;
  78.                 keyInfo=KeyTrans(pKCHR,keyCode,&state);
  79.                 if((keyInfo&charCodeMask) == '.' 
  80.                     || ((keyInfo>>16)&charCodeMask) == '.')isCmdPeriod=TRUE;
  81.                 if (hKCHR != NULL) ReleaseResource(hKCHR);
  82.             }else if((event->message&charCodeMask) == '.')isCmdPeriod=TRUE;
  83.             if(isCmdPeriod)period=event->message&charCodeMask;
  84.         }
  85.         return isCmdPeriod;
  86.     }
  87. }
  88.