问题描述
我在寻找从一个Android的NativeActivity的软键盘获取输入的方式。
I'm looking for a way of getting input from the software keyboard from a Android NativeActivity.
我发现这,它提供了一些样品$ C $如何获得软键盘了(和它的作品),但缺乏兴趣几点C:
I found this, that provides some sample code of how to get the software keyboard out (and it works), but lacks a few points of interest:
- 如何获得键盘的输入显示一次。
- 如何避免应用程序,当用户使用后退按钮关闭键盘崩溃。
如果任何人有任何的答案要么这些问题,或者更好的,这表明不要求使用JNI的键盘更简单的方法,请分享。
If anyone has any answers to either of these questions, or better yet, a simpler way of showing the keyboard that does not require the use of JNI, please share.
在此先感谢,
海梅
推荐答案
如果有人想知道,您可以访问键盘输入通常的方式,在回调分配到结构android_app你在哪里得到的AInputEvents:
If anyone wonders, you access keyboard input the usual way, in your callback assigned to the struct android_app where you get the AInputEvents:
if (AInputEvent_getType(event) == AINPUT_EVENT_TYPE_KEY)
{
lint32_t key_val = AKeyEvent_getKeyCode(event);
fprintf("Received key event: %d\n", key_val);
if((key_val >= AKEYCODE_A && key_val <= AKEYCODE_Z))
{
fprintf("Got a letter");
}
return 0;
}
您也可以访问其他的硬件按钮,在这里通过检查关键codeS如AKEY code_BACK或AKEY code_VOLUME_UP。
You can also get access to other "hardware" buttons here by checking against key codes such as AKEYCODE_BACK or AKEYCODE_VOLUME_UP.
这篇关于在Android中使用NDK NativeActivity的键盘输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!