Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

MACaveli7

macrumors newbie
Original poster
Oct 15, 2010
23
0
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);
}
 

MACaveli7

macrumors newbie
Original poster
Oct 15, 2010
23
0
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.