Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get user soft keyboard input on Android platform #3275

Closed
YuDang1024 opened this issue Jun 1, 2020 · 6 comments
Closed

How to get user soft keyboard input on Android platform #3275

YuDang1024 opened this issue Jun 1, 2020 · 6 comments

Comments

@YuDang1024
Copy link

I am using imgui on Android platform now,
But I cannot wake up the user's local input method in the text input box。
So far I thought of a solution, although it is not ideal, but the guess is available。
I use Andorid's native UI component: TextInput, but I set it to transparent or very small, so small that the user cannot see.
Then wake up the input method through this TextInput component, and then obtain the user's input through the interface provided by this component.

I haven't verified this method because I think this method is not a good solution, but I can't think of another solution.
Do you have any better suggestions or solutions?

@YuDang1024
Copy link
Author

If there is an iOS platform, the related solutions can help me. I think the solutions for the two platforms should be universal.
If I find a suitable solution, I will reply to tell you in this post

@rokups
Copy link
Contributor

rokups commented Jun 1, 2020

Hey @YuDang1024,
Soft keyboard is supposed to be handled by the backend based on ImGuiIO::WantCaptureKeyboard flag. For example, in SDL you are supposed to call SDL_SetTextInputRect and SDL_StartTextInput when ImGuiIO::WantCaptureKeyboard == true. You may use SDL on both android and iOS.

@ocornut
Copy link
Owner

ocornut commented Jun 1, 2020

On Dear ImGui side, you should read io.WantTextInput as explained in the FAQ
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-to-my-application

On Android side, you should definitively open the Android on-screen keyboard when io.WantTextInput is set. For this you'll need to look up in Android documentation.

@YuDang1024
Copy link
Author

On Dear ImGui side, you should read io.WantTextInput as explained in the FAQ
https://github.com/ocornut/imgui/blob/master/docs/FAQ.md#q-how-can-i-tell-whether-to-dispatch-mousekeyboard-to-dear-imgui-or-to-my-application

On Android side, you should definitively open the Android on-screen keyboard when io.WantTextInput is set. For this you'll need to look up in Android documentation.

I used the soft keyboard on Android according to your suggestion before, but because the soft keyboard is used on the Android platform, I need to use native components as a carrier, and after awakening the soft keyboard, I did not get user input in the input box of Dear ImGui.
Maybe I am not very skilled in the Android platform.
But now I have found a way to solve the problem: it is to draw 26 buttons and act as a virtual keyboard, which can solve my problem and the effect is not bad. thanks for your help.

@YuDang1024
Copy link
Author

Hey @YuDang1024,
Soft keyboard is supposed to be handled by the backend based on ImGuiIO::WantCaptureKeyboard flag. For example, in SDL you are supposed to call SDL_SetTextInputRect and SDL_StartTextInput when ImGuiIO::WantCaptureKeyboard == true. You may use SDL on both android and iOS.

Hey @YuDang1024,
Soft keyboard is supposed to be handled by the backend based on ImGuiIO::WantCaptureKeyboard flag. For example, in SDL you are supposed to call SDL_SetTextInputRect and SDL_StartTextInput when ImGuiIO::WantCaptureKeyboard == true. You may use SDL on both android and iOS.

Because I don’t know much about SDL, after receiving your suggestion, I didn’t have the first time to integrate SDL in the project, but I drew 26 buttons to act as my keyboard. , SDL may be a better solution

@rokups
Copy link
Contributor

rokups commented Jun 2, 2020

I used the soft keyboard on Android according to your suggestion before, but because the soft keyboard is used on the Android platform, I need to use native components as a carrier, and after awakening the soft keyboard, I did not get user input in the input box of Dear ImGui.

This is exactly what SDL does for you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants