I’m trying to use UltraLight (a embedded HTML renderer) inside JUCE, where keyboard events need to be injected. I wrote following code to handle text input:
class UltraLightComponent: public juce::Component
{
// ......
bool keyPressed( const juce::KeyPress& key ) override;
// ......
};
bool UltraLightComponent::keyPressed( const juce::KeyPress& k )
{
// ......
// inject text input
char32_t text_char = (char32_t) k.getTextCharacter();
if ( text_char != 0 )
{
DBG( "text character: " + juce::String::toHexString( text_char ) );
ultralight::KeyEvent text_key;
text_key.type = ultralight::KeyEvent::kType_Char;
text_key.text = ultralight::String32{ &text_char, 1 };
guts->view->FireKeyEvent( text_key );
}
// ......
}
It works fine when I type in English characters from keyboard directly. But when I type in Chinese characters using input method (actually the one from Microsoft), getTextCharacter()
always return zero. So is there any extra things I should do to make JUCE components handle IME?