home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
MacFormat España 21
/
macformat_21.iso
/
Shareware
/
Programación
/
VideoToolbox
/
VideoToolboxSources
/
IsCmdPeriod.c
< prev
next >
Wrap
Text File
|
1996-06-06
|
5KB
|
113 lines
/*
IsCmdPeriod.c
You pass it an event record and it tells you whether or not the user has hit
command-period (i.e. "cancel"). This method should work on all Macs, including
international MacOS that remap the keyboard.
WARNING:
The simple call probably works fine, but I haven't tested it.
Nor have I tested the elaborate scheme. I haven't read the Script Manager chapter. The caching
scheme (saving "period") might fail if you change script systems between calls
to IsCmdPeriod.
Copied from comp.sys.mac.programming:
From: k044477@hobbes.kzoo.edu (Jamie R. McCarthy)
Date: 13 May 93 19:41:38 GMT
Organization: Kalamazoo College
>PLEASE everybody read the "International Canceling" tech note (in
>"Text"), or in the official jargon: M.TE.InternationalCancel (yech).
>
>It explains that Command key combinations with non-letter keys may
>map to Command-Shift key codes on international keyboards. And we
>all know that Command-Shift gets intercepted by the operating system.
>This is a pain, because it means you won't be able to cancel operations,
>or have access to similar keyboard shortcuts.
Here's the function I use. I think I took it pretty much straight from
the TN, but I might have made some minor improvement, I don't recall
what. Anyway, maybe this'll save someone a few minutes' worth of
typing:
- --
Jamie McCarthy Internet: k044477@kzoo.edu AppleLink: j.mccarthy
HISTORY:
13 May 93 Jamie McCarthy posted it on comp.sys.mac.programming
6/23/93 dgp corrected bug of using "=" instead of "==" in an if statement.
Check for valid handle before dereferencing. Tightened up code a bit.
Not tested.
6/30/93 dgp The elaborate method required for international systems seems
excessive for routine use, so I added a shortcut. We go through the whole
rigamarole once, and note what the Cmd-period key presses were translated to.
On subsequent occasions we just (quickly) check for that.
5/22/95 dgp Apple changed the prototype from KeyTrans(...,long *state)
to KeyTranslate(...,unsigned long *state). To make the code compatible
with both versions, I cast the argument as (void *).
11/10/95 dgp Daniel Sears, sears@netcom.com, writes "IsCmdPeriod.c should take advantage of
IsCmdChar(event, '.'), which is international and was divulged in a Develop Q/A."
I looked for this on the current Apple Developer CD (November '95) and the two preceding ones,
and can't find it.I did find Tech Note TE 23 International Canceling, dated 1990, which
clearly predates the existence of IsCmdChar and goes into a long
explanation and supplies sample code, which I suppose is the basis of what's below, though
I haven't checked. I did find the prototype for IsCmdChar in Script.h though, and went ahead and made
the change, as suggested by Dan.
*/
#include "VideoToolbox.h"
//#include <Types.h>
//#include <Script.h>
//#include <OSUtils.h>
#if !UNIVERSAL_HEADERS
extern pascal Boolean IsCmdChar(const EventRecord *event, short test)={0x2F3C,0x8206,0xFFD0,0xA8B5};
#endif
Boolean IsCmdPeriod(register EventRecord *event)
{
static char period=0; // what cmd-period gets mapped to.
static Boolean firstTime=1,trapAvailable;
if(firstTime){
// I don't know whether this test is sufficient to guarantee presence of IsCmdChar().
#define _ScriptUtil 0xA8B5
trapAvailable=TrapAvailable(_ScriptUtil);
firstTime=0;
}
if(trapAvailable)
return IsCmdChar(event,'.'); // prototype in Script.h. Documented in Mac Tech Q&A??
else{
if(period!=0) return (event->what == keyDown || event->what == autoKey)
&& (event->modifiers & cmdKey)
&& (event->message & charCodeMask) == period;
else{
Boolean isCmdPeriod=FALSE;
short keyCode;
long keyInfo,keyCID;
unsigned long state;
Handle hKCHR;
Ptr pKCHR;
if ((event->modifiers & cmdKey)
&& (event->what == keyDown || event->what == autoKey)){
pKCHR=(Ptr)GetEnvirons(smKCHRCache); // returns NULL under System 6
if(pKCHR == NULL){
keyCID=GetScript(GetEnvirons(smKeyScript),smScriptKeys);
hKCHR=GetResource('KCHR',keyCID);
if(hKCHR!=NULL)pKCHR=*hKCHR;
}else hKCHR=NULL;
if(pKCHR != NULL){
// re-translate the virtual key to a char, without the command modifier
keyCode=(event->message & keyCodeMask) >> 8; // the virtual key
keyCode |= event->modifiers & 0xFF00 & ~cmdKey;
state=0;
keyInfo=KeyTrans(pKCHR,keyCode,(void *)&state); // compatible with all prototypes
if((keyInfo&charCodeMask) == '.'
|| ((keyInfo>>16)&charCodeMask) == '.')isCmdPeriod=TRUE;
if (hKCHR != NULL) ReleaseResource(hKCHR);
}else if((event->message&charCodeMask) == '.')isCmdPeriod=TRUE;
if(isCmdPeriod)period=event->message&charCodeMask;
}
return isCmdPeriod;
}
}
}