Created
July 5, 2013 08:12
-
-
Save adamjs/5932868 to your computer and use it in GitHub Desktop.
crude demonstration of how to handle SDL_TEXTINPUT (SDL 2.0) with Awesomium's WebKeyboardEvent API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
void handleTextInputEvent(const SDL_Event& event) { | |
Awesomium::WebKeyboardEvent keyEvent; | |
keyEvent.type = Awesomium::WebKeyboardEvent::kTypeChar; | |
// WebKit's WebKeyboardEvent only supports up to 4 chars per "text" event | |
// but SDL supports up to 32 chars. If we really wanted to do this right, | |
// we'd probably need to inject several events for text > 4 chars. | |
// Let's just trim it down to 4 for now. | |
for (int i = 0; i < 4; i++) { | |
keyEvent.text[i] = (wchar16)event.text.text[i]; | |
keyEvent.unmodified_text[i] = (wchar16)event.text.text[i]; | |
} | |
// Use the first character of the text as the 'key code' | |
keyEvent.virtual_key_code = (wchar16)event.text.text[0]; | |
keyEvent.native_key_code = (wchar16)event.text.text[0]; | |
webView->InjectKeyboardEvent(keyEvent); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment