Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Stripping modifier keys



Marco,
you'll want to look at the new TextInputSource (TIS) API avaiiable in Leopard HIToolbox (TextInputSources.h).  The TIS API supercedes the deprecated KL API and will be available in 64bit.  Hope the following snippet helps:


TISInputSourceRef    kbInputSourceRef = (TSMInputSourceRef) TISCopyCurrentKeyboardLayoutInputSource();
// Get the 'uchr' data
CFDataRef uchrDataRef = (CFDataRef)TISGetInputSourceProperty( kbInputSourceRef, kTISPropertyUnicodeKeyLayoutData );
Boolean existsUchr = ( (uchrDataRef != NULL) && (CFDataGetBytePtr(uchrDataRef) != NULL) && (CFDataGetLength(uchrDataRef) != 0) );
  if (existsUchr) {
UInt32 modifiers = 0; // If you're getting this from a CarbonEvent, you'll want to right-shift...  i.e.,   modifiers >> 8 below
UInt32 deadKeyState = 0;
UniChar   *uCharsOut = malloc( ... );
UniCharCount numUCharsOut;

OSStatus status = UCKeyTranslate( (const UCKeyboardLayout *)CFDataGetBytePtr( uchrDataRef ),
keyCode, kUCKeyActionDown,
modifiers, LMGetKbdType(), kUCKeyTranslateNoDeadKeysMask /*or kNilOptions*/,
&deadKeyState, maxUnicodeStrLength, &numUCharsOut, uCharsOut );
  }
  CFRelease(kbInputSourceRef);

Michael Grady


On Jun 20, 2007, at 8:36 AM, Marco Piovanelli wrote:

When the user enters some modifier+key combinations, I'd

like to find out what string of UniChars would have been

generated if no modifiers had been used.


Is there a way to do this in a future-compatible way without

resorting to a combination of KLGetCurrentKeyboardLayout,

KLGetKeyboardLayoutProperty, UCKeyTranslate and KeyTranslate,

which seems pretty convoluted for a simple task like this?


TIA,



                                        -- marco


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden

This email sent to email@hidden

References: 
 >Stripping modifier keys (From: "Marco Piovanelli" <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.