分类: android2013-05-08 10:48 202人阅读 评论(0) 收藏 举报 android4.0 按键消息响应流
1.开始肯定先说的是驱动这块,硬件是软件服务的,在Android这块C和java交互,有两种方式:
-
static jboolean
- android_server_KeyInputQueue_readEvent(JNIEnv* env,jobject clazz,
-
jobject event) - {
-
gLock.lock(); -
sp hub = gHub; -
if(hub == NULL) { -
hub = new EventHub; -
gHub = hub; -
} -
gLock.unlock(); -
-
int32_t deviceId; -
int32_t type; -
int32_t scancode, keycode; -
uint32_t flags; -
int32_t value; -
nsecs_t when; -
boolres = hub->getEvent(&deviceId,&type, &scancode,&keycode, -
&flags, &value,&when); -
-
env->SetIntField(event, gInputOffsets.mDeviceId,(jint)deviceId); -
env->SetIntField(event, gInputOffsets.mType,(jint)type); -
env->SetIntField(event, gInputOffsets.mScancode,(jint)scancode); -
env->SetIntField(event, gInputOffsets.mKeycode,(jint)keycode); -
env->SetIntField(event, gInputOffsets.mFlags,(jint)flags); -
env->SetIntField(event, gInputOffsets.mValue,value); -
env->SetLongField(event, gInputOffsets.mWhen, -
(jlong)(nanoseconds_to_milliseconds(when))); -
-
returnres; - }