Re: Key number to Unicode string
Re: Key number to Unicode string
- Subject: Re: Key number to Unicode string
- From: Daniel Jalkut <email@hidden>
- Date: Thu, 7 Jun 2007 13:47:27 -0400
I ran into this problem recently. A friend pointed me to using
Keyboard Layout Services instead:
http://developer.apple.com/documentation/Carbon/Reference/
KeyboardLayoutServices/Reference/reference.html
The older GetScriptVariable type approach seems to not work anymore,
as you've discovered.
In particular look (and google maybe) at KLGetKeyboardLayoutProperty.
--------------
Daniel Jalkut
http://www.red-sweater.com/blog/
On Jun 7, 2007, at 11:48 AM, email@hidden wrote:
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:
sweater.com
This email sent to email@hidden
_______________________________________________
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
- Prev by Date:
NSArrayController display newly inserted objects twice Hi guys ! I'm facing a strange problem with an instance of NSArrayController. In my project, I have an entity with an attribute named "name". This attribute have to be unique, so I have a validation process that ensure the uniqueness : - (BOOL)validateName: (id *)valueRef error:(NSError **)outError { // "name" must be unique NSArray * results = nil; NSPredicate * predicate = nil; NSFetchRequest * fetchRequest = nil; predicate = [NSPredicate predicateWithFormat:@"(SELF != %@) AND (name LIKE %@)", self, *valueRef]; fetchRequest = [[[NSFetchRequest alloc] init] autorelease]; [fetchRequest setEntity:[self entity]]; [fetchRequest setPredicate:predicate]; results = [[self managedObjectContext] executeFetchRequest:fetchRequest error:nil]; if ( [results count] > 0 ) { return NO; } return YES; } I've also added the following methods to ensure that any newly inserted object has a unique name by defa! ult : ! - (void)awakeFromInsert { [self setUniqueName]; } - (void)setUniqueName { NSString * defaultName = NSLocalizedStringFromTableInBundle(@"NewCategory", @"Localizable", [NSBundle mainBundle], nil); NSString * uniqueName = defaultName; int index = 0; NSError * error = nil; while ( ![self validateValue:&uniqueName forKey:@"name" error:&error] ) { index++; uniqueName = [defaultName stringByAppendingFormat:@" (%d)", index]; break; } [self setName: uniqueName]; } This works perfectly in most cases...but the most important one : insertion using an NSArrayController. In this case, my managed object is inserted perfectly in the database, with a unique name, but the array controller inserts it twice in its content array ! It seems like the problem is due to this line in my validation method : results = [[self managedObjectContext] executeFetchRequest:fetchRequest error:nil]; If I comment this line, everything works perfectly (but, obviously, the name is not unique). To ill! ustrat! e the problem, I've created a small project that can be do
- Next by Date:
NSArrayController display newly inserted objects twice
- Previous by thread:
Key number to Unicode string
- Next by thread:
Re: Key number to Unicode string
- Index(es):