Param error in UCKeyTranslate()

Discussion in 'Mac Programming' started by MACaveli7, Oct 15, 2010.

  1. macrumors newbie

    Oct 15, 2010
    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);
  2. macrumors 604

    Aug 9, 2009
    Which error is it returning?

    What have you already tried to debug this?
  3. thread starter macrumors newbie

    Oct 15, 2010
    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.
  4. macrumors 604

    Aug 9, 2009

Share This Page