• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Key number to Unicode string
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Key number to Unicode string


  • Subject: Key number to Unicode string
  • From: email@hidden
  • Date: Thu, 7 Jun 2007 19:48:20 +0400

Hello,

I write application a-la standard osx Keyboard Viewer. I need convert
key code to corresponding unicode char (using current input language).

KeyTranslate/UCKeyTranslate working fine only with English/French
layouts, but with Russian layout it returns english chars!

What the way to retrieve right symbols?

Here is code:

unichar KeyCodeToUnicode(UInt16 virtualKeyCode )
{
	unsigned long state;
	SInt16 currentKeyScript;
   SInt16 lastKeyLayoutID;

	unichar str[10];
	UniCharCount actualLength;
	UInt32 deadKeyState = 0;

	char restype[] = "uchr";
	ResType* rt = (ResType*)restype;

	currentKeyScript = GetScriptManagerVariable(smKeyScript);
   lastKeyLayoutID = GetScriptVariable(currentKeyScript, smScriptKeys);

   deadKeyState = 0;
	Handle hh = GetResource(*rt, lastKeyLayoutID);

	if( hh )
	{
		UCKeyTranslate (
			(const UCKeyboardLayout *)*hh,
			virtualKeyCode,
			kUCKeyActionDown,
			0,
			LMGetKbdType(),
			0, // OptionBits keyTranslateOptions,
			&deadKeyState,
			sizeof(str)/sizeof(unichar),
			&actualLength,
			str
			);
	}

	return str[0];
}

Thanks.
_______________________________________________

Cocoa-dev mailing list (email@hidden)

Do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Follow-Ups:
    • Re: Key number to Unicode string
      • From: Daniel Jalkut <email@hidden>
  • Prev by Date: Re: codeSense
  • Next by Date: Re: NSTable - intercept item name before user editing
  • Previous by thread: Re: Dictionaries within a dictionary - getAllValuesForKey:
  • Next by thread: Re: Key number to Unicode string
  • Index(es):
    • Date
    • Thread