My Edit boxes don't work anymore

Captain_Deathbeard

22-07-2010 15:54:40

Its probably something stupid, but I have noticed that my Edit boxes don't work. They used to, ages ago when I last tested them. It could possibly be since I updated to MyGUI3.0.1.
I get focus, I can click in them and even select and delete text. But if I type letters nothing comes out.
I'm definitely injecting key presses:
virtual bool keyPressed( const OIS::KeyEvent& vEvent ) {
gui.getGuiManager()->injectKeyPress(MyGUI::KeyCode::Enum(vEvent.key));


Did any change happen in the v3 update perhaps that might affect edit widgets? Any ideas what my problem points to?

Altren

22-07-2010 19:48:01

Now you also need to give character code to MyGUI, here's code used in demos:
MyGUI::Char translateWin32Text(MyGUI::KeyCode kc)
{
static WCHAR deadKey = 0;

BYTE keyState[256];
HKL layout = GetKeyboardLayout(0);
if ( GetKeyboardState(keyState) == 0 )
return 0;

int code = *((int*)&kc);
unsigned int vk = MapVirtualKeyEx((UINT)code, 3, layout);
if ( vk == 0 )
return 0;

WCHAR buff[3] = { 0, 0, 0 };
int ascii = ToUnicodeEx(vk, (UINT)code, keyState, buff, 3, 0, layout);
if (ascii == 1 && deadKey != '\0' )
{
// A dead key is stored and we have just converted a character key
// Combine the two into a single character
WCHAR wcBuff[3] = { buff[0], deadKey, '\0' };
WCHAR out[3];

deadKey = '\0';
if(FoldStringW(MAP_PRECOMPOSED, (LPWSTR)wcBuff, 3, (LPWSTR)out, 3))
return out[0];
}
else if (ascii == 1)
{
// We have a single character
deadKey = '\0';
return buff[0];
}
else if(ascii == 2)
{
// Convert a non-combining diacritical mark into a combining diacritical mark
// Combining versions range from 0x300 to 0x36F; only 5 (for French) have been mapped below
// http://www.fileformat.info/info/unicode/block/combining_diacritical_marks/images.htm
switch(buff[0]) {
case 0x5E: // Circumflex accent: в
deadKey = 0x302; break;
case 0x60: // Grave accent: а
deadKey = 0x300; break;
case 0xA8: // Diaeresis: ь
deadKey = 0x308; break;
case 0xB4: // Acute accent: й
deadKey = 0x301; break;
case 0xB8: // Cedilla: з
deadKey = 0x327; break;
default:
deadKey = buff[0]; break;
}
}

return 0;
}

bool InputManager::keyPressed(const OIS::KeyEvent& _arg)
{
MyGUI::Char text = (MyGUI::Char)_arg.text;
MyGUI::KeyCode key = MyGUI::KeyCode::Enum(_arg.key);
int scan_code = key.toValue();

if (scan_code > 70 && scan_code < 84)
{
static MyGUI::Char nums[13] = { 55, 56, 57, 45, 52, 53, 54, 43, 49, 50, 51, 48, 46 };
text = nums[scan_code-71];
}
else if (key == MyGUI::KeyCode::Divide)
{
text = '/';
}
else
{
#if MYGUI_PLATFORM == MYGUI_PLATFORM_WIN32
text = translateWin32Text(key);
#endif
}

MyGUI::InputManager::getInstance().injectKeyPress(key, text);
return true;
}


You can use much shorter variant - something like gui.getGuiManager()->injectKeyPress(MyGUI::KeyCode::Enum(vEvent.key), (MyGUI::Char)vEvent.text);but OIS not always gives proper characters.

Captain_Deathbeard

23-07-2010 00:11:47

Thank you very much!