[comp.sys.mac.programmer] Masking Modified Characters

minow@mountn.dec.com (Martin Minow) (08/16/90)

In article <3903@husc6.harvard.edu> siegel@endor.UUCP (Rich Siegel) writes:
>How does one avoid getting option-generated characters when using
>GetNextEvent?
>For example, when I type Command-Option-P, I'll an event which tells me I've
>typed Command-Option-pi, and I'm more interested in what the unmodified 
>character was. Is there a standard mask for turning modified characters into
>standard ones, or is there some other hack?

Hi Rich.  You won't like this answer: I "solved" the problem by building
my very own hack KCHR resource that had no option tables.  You have to
make sure you switch back to the original KCHR when your application
exits (or multifinder switches).  This is definately a "kids, don't
try this at home" trick; send me mail if you want the code.

Martin.
minow@bolt.enet.dec.com

dorner@pequod.cso.uiuc.edu (Steve Dorner) (08/16/90)

In article <3903@husc6.harvard.edu> siegel@endor.UUCP (Rich Siegel) writes:
>How does one avoid getting option-generated characters when using GetNextEvent?
>For example, when I type Command-Option-P, I'll an event which tells me I've
>typed Command-Option-pi, and I'm more interested in what the unmodified 
>character was. Is there a standard mask for turning modified characters into
>standard ones, or is there some other hack?

I have a hack; it's the best way I could come up with, and I think it's
compatible, at least with 8 bit languages.  Comments, anyone?


/************************************************************************
 * UnadornMessage - unadorn an event message
 ************************************************************************/
long UnadornMessage(EventRecord *event)
{
  long message;
  Handle curKCHR;
  static long state=0;
  short key;
  
  curKCHR = GetResource('KCHR',
		      GetScript(GetEnvirons(smKeyScript),smScriptKeys));
  if (!curKCHR || !event->modifiers&optionKey)
    message = event->message;
  else
  {
    /*
     * get what it would have been without the option key
     */
    key = ((event->message>>8)&0xff) | (event->modifiers&(~optionKey)&0xff00);
    message = KeyTrans(LDRef(curKCHR),key,&state);
    
    /*
     * now massage this into an event "message"
     */
    message = (message & 0xff) | (event->message & 0xff00);
  }
  
  return(message);
}

--
Steve Dorner, U of Illinois Computing Services Office
Internet: s-dorner@uiuc.edu  UUCP: {convex,uunet}!uiucuxc!dorner

jackiw@cs.swarthmore.edu (Nick Jackiw) (08/16/90)

Rich Siegel writes:
.How does one avoid getting option-generated characters when using GetNextEvent?
.For example, when I type Command-Option-P, I'll an event which tells me I've
.typed Command-Option-pi, and I'm more interested in what the unmodified 
.character was. Is there a standard mask for turning modified characters into
.standard ones, or is there some other hack?

Martin Minow replies:
.Hi Rich.  You won't like this answer: I "solved" the problem by building
.my very own hack KCHR resource that had no option tables.  You have to
.make sure you switch back to the original KCHR when your application
.exits (or multifinder switches).  This is definately a "kids, don't
.try this at home" trick; send me mail if you want the code.

Steve Dorner posts code:
.I have a hack; it's the best way I could come up with, and I think it's
.compatible, at least with 8 bit languages.  Comments, anyone?
[Code deleted]

Steve's method is the sanctioned one (cf. TechNote#263), but assumes
that the proper keycode is stored in the low-byte of KeyTrans' return.
This is apparently incorrect; the byte it returns in is either high
or low (I think depending on the script).  The illustration (Figure 7,
V-195) implies it's in the low byte, but it's an example, not a rule.

If you're checking to see if keyCode = some specific option+whatever,
you can check ((whatever=maskedKey mod 256) or (whatever=maskedKey div 256));
on the other hand, if you need it to return an arbitrary maskedKey, I'm
not sure how you can tell which of the two bytes contains the keycode.
Perhaps check against some known value?  Even this seems keyboard/script
specific.

Just another cook for your soup,


-- 
-----Nick Jackiw [jackiw@cs.swarthmore.edu|jackiw@swarthmr.bitnet------
"This orbe of starres fixed infinitely vp extendeth hitself in altitvde 
sphericallye, and therefore immovable the pallace of foelicity garnished
with perpetvall shining glorious lightes innvmerable." - Thomas Digges

jackiw@cs.swarthmore.edu (Nick Jackiw) (08/16/90)

Oops...memory error in that last post.  Turns out the ambiguity is in
which *word* of its longword result _KeyTrans puts your keycode in.
Within that word, it's always in the low-order byte.  Sorry for any
confusion.



-- 
-----Nick Jackiw [jackiw@cs.swarthmore.edu|jackiw@swarthmr.bitnet------
"This orbe of starres fixed infinitely vp extendeth hitself in altitvde 
sphericallye, and therefore immovable the pallace of foelicity garnished
with perpetvall shining glorious lightes innvmerable." - Thomas Digges

lsr@Apple.COM (Larry Rosenstein) (08/16/90)

In article <3903@husc6.harvard.edu> siegel@endor.UUCP (Rich Siegel) writes:

>character was. Is there a standard mask for turning modified characters into
>standard ones, or is there some other hack?

I think you could do something similar to Tech Note 263 (which talks about
detecting command-period in all international systems).  Basically, you
strip off the option modifier and run the raw keycode back through the
keyboard mapping software.



-- 
		 Larry Rosenstein,  Object Specialist
 Apple Computer, Inc.  20525 Mariani Ave, MS 46-B  Cupertino, CA 95014
	    AppleLink:Rosenstein1    domain:lsr@Apple.COM
		UUCP:{sun,voder,nsc,decwrl}!apple!lsr

russotto@eng.umd.edu (Matthew T. Russotto) (08/17/90)

In article <1857@mountn.dec.com> minow@bolt.enet.dec.com.UUCP (Martin Minow) writes:
>In article <3903@husc6.harvard.edu> siegel@endor.UUCP (Rich Siegel) writes:
>>How does one avoid getting option-generated characters when using
>>GetNextEvent?
>>For example, when I type Command-Option-P, I'll an event which tells me I've
>>typed Command-Option-pi, and I'm more interested in what the unmodified 
>>character was. Is there a standard mask for turning modified characters into
>>standard ones, or is there some other hack?
>
[some other hack omitted]

How about looking up the key code in the KCHR (and ignoring the system provided
char code entirely)?

The routine KeyTrans should do it for you.
--
Matthew T. Russotto	russotto@eng.umd.edu	russotto@wam.umd.edu
][, ][+, ///, ///+, //e, //c, IIGS, //c+ --- Any questions?

minow@mountn.dec.com (Martin Minow) (08/18/90)

In article <T43NJGC@cs.swarthmore.edu> jackiw@cs.swarthmore.edu
(Nick Jackiw) writes:

>Steve's method [get the keycode from the event and call KeyTrans on
>the code with the optionKey modifier masked out] is the sanctioned one (cf.
>TechNote#263), but assumes
>that the proper keycode is stored in the low-byte of KeyTrans' return.

I think the reason I didn't use this method is that I needed to handle
the dead-keys (option-E, for example) as any other key -- this was for a
terminal emulator that did Dec LK201 "compose" properly.   Can Steve's
method let me type Option-E/Shift-6 (E-circumflex in Dec Compose mode)?

Martin.
minow@bolt.enet.dec.com