PDA

View Full Version : Param error in UCKeyTranslate()




MACaveli7
Oct 15, 2010, 09:27 AM
Does anyone know why the below code is causing UCKeyTranslate to return an error?

const int kBuffSize = 16;

MacTypes::TSMDocumentID idocID;

MacTypes::OSType types[1];
types[0] = MacTypes::kUnicodeDocument;

MacTypes::NewTSMDocument(1, types, &idocID,0);

const MacTypes::UCKeyboardLayout* uchrHandle;
MacTypes::UInt32 deadKeyState = 0;
MacTypes::SInt16 currentKeyScript;
MacTypes::SInt16 lastKeyLayoutID;
MacTypes::UniChar unicodeInputString[kBuffSize];

MacTypes::UInt32 keyboardType;
MacTypes::UInt32 modifierKeyState;
MacTypes::UInt16 virtualKeyCode;
MacTypes::UInt16 keyAction;
MacTypes::UniCharCount actualStringLength;

keyAction = MacTypes::kUCKeyActionDown;
modifierKeyState = 0;
keyboardType = MacTypes::LMGetKbdType();

currentKeyScript = GetScriptManagerVariable(MacTypes::smKeyScript);

lastKeyLayoutID = GetScriptVariable(currentKeyScript, MacTypes::smScriptKeys);

//uchrHandle = MacTypes::GetResource('uchr', lastKeyLayoutID);
uchrHandle = (const MacTypes::UCKeyboardLayout*)MacTypes::GetResource('uchr', 0);

if (uchrHandle)
{
MacTypes::OSStatus status = MacTypes::UCKeyTranslate(uchrHandle, uVirtualKey,keyAction, modifierKeyState, keyboardType, 0, &deadKeyState,
kBuffSize, &actualStringLength, unicodeInputString);
}



chown33
Oct 15, 2010, 12:34 PM
Which error is it returning?

What have you already tried to debug this?

MACaveli7
Oct 17, 2010, 04:55 AM
It is returning a param error (-50), I think it is because the second parameter of the GetResource function is set to zero. I set it to zero because when I used 'lastKeyLayoutID', uchr returned 'invalid'. I'm assuming that in that case I should use the KCHR resource for ascii input instead. So the question is why don't I have the 'uchr' resource for the lastKeyLayoutID on my machine, this question might seem niave but I am a newbie to Mac programming.

chown33
Oct 18, 2010, 01:23 PM
If you're new to Mac programming, what are you trying to accomplish that needs keycode transformation into Unicode?

Have you seen these:
http://www.cocoabuilder.com/archive/cocoa/184332-key-number-to-unicode-string.html
http://lists.apple.com/archives/Carbon-dev/2008/Jan/msg00012.html