andyhebear1
08-06-2010 10:48:57
MyGUI::Char getKeyChar(void); 返回每次输入得到的字符(没有打开输入法的时候)。
剩下的就是自己处理中文输入的问题了 : )
///简单的代码如下:
bool Listener::keyPressed ( const OIS::KeyEvent &arg )
{
///打开输入法后的字符处理
if(ImmIsIME(GetKeyboardLayout(0)))
{
///中文输入及数字键输入
if(arg.key == OIS::KC_BACK)
{
GHyGuiManagerPtr->keyPressed(arg);
///得到文本光标的位置
pos = GHyGuiMainWindowPtr->getTextCursor();
///保存最新的文本
deleteText(pos);
///更新聊天框文本
GHyGuiMainWindowPtr->setText(getTextContainer());
///更新光标的位置
GHyGuiMainWindowPtr->setTextCursor(pos);
}
else if(arg.key == OIS::KC_SPACE ||
arg.key == OIS::KC_0 ||
arg.key == OIS::KC_1 ||
arg.key == OIS::KC_2 ||
arg.key == OIS::KC_3 ||
arg.key == OIS::KC_4 ||
arg.key == OIS::KC_5 ||
arg.key == OIS::KC_6 ||
arg.key == OIS::KC_7 ||
arg.key == OIS::KC_8 ||
arg.key == OIS::KC_9)
{
///保存到容器
std::string str = lpGetString();///截取中文字符串
///收集汉字字符
getTextContainer(str);
unsigned int num = 0;
///插入字符串及更新相关信息
for(VECSTR::iterator it = mCNSContainer.begin(); it != mCNSContainer.end(); ++it)
{
///得到文本光标的位置
pos = GHyGuiMainWindowPtr->getTextCursor();
///插入汉字字符串
insertText(pos + num + 1,(*it));
///更新聊天框文本
GHyGuiMainWindowPtr->setText(getTextContainer());
///更新光标的位置
GHyGuiMainWindowPtr->setTextCursor(pos + 1);
}
}
return false;
}
//////关闭输入法后的字符处理
else
{
///如果按退格键
if(arg.key == OIS::KC_BACK)
{
///继续处理按键输入(删除)
GHyGuiManagerPtr->keyPressed(arg);
///得到文本光标的位置
pos = GHyGuiMainWindowPtr->getTextCursor();
///保存最新的文本
deleteText(pos);
///更新聊天框文本
GHyGuiMainWindowPtr->setText(getTextContainer());
///更新光标的位置
GHyGuiMainWindowPtr->setTextCursor(pos);
}
else
{
///处理按键输入(插入)
GHyGuiManagerPtr->keyPressed(arg);
///得到文本光标的位置
pos = GHyGuiMainWindowPtr->getTextCursor();
///保存到容器
std::string str;
str.push_back(GHyGuiManagerPtr->getKeyChar());
///插入字符
insertText(pos,str);
///更新聊天框文本
GHyGuiMainWindowPtr->setText(getTextContainer());
///更新光标的位置
GHyGuiMainWindowPtr->setTextCursor(pos + 1);
}
}
return true;
}
this is in c++ code! but in MyGui.Managed ,what can i do that!