我编写 C 代码来读取 /dev/input/event0,然后读取 rawX 和 rawY,但是在 Activity OnTouch 函数中,我得到 x 和 y,它们不等于 rawX 和 rawY。我知道他们有关系,但我不知道如何转换。也许某些文件中的某些内容可以让我转换它们?
C代码如下:
while (!is_stop) {
read(fd, &ev, sizeof(struct input_event));
switch (ev.type) {
case EV_SYN:
if(x != 0 && y != 0) {
(*env)->SetIntField(env,obj, x_id, x);
(*env)->SetIntField(env, obj, y_id, y);
}
//LOGI("sync");
break;
case EV_KEY:
if (ev.code == BTN_TOUCH) {
if (ev.value == 1) { // finger down
LOGI("finger down,keycode is %d keyvalue is %d", ev.code, ev.value);
} else if (ev.value == 0) { //finger up,上一次x,y是0
finger_up = 1;
LOGI("finger up,keycode is %d keyvalue is %d", ev.code, ev.value);
}
}
break;
case EV_ABS:
if (ev.code == ABS_X) {
LOGI("abs_x:%d\n", ev.value);
x = ev.value;
}
else if (ev.code == ABS_Y) {
LOGI("abs_y:%d\n", ev.value);
y = ev.value;
}
break;
default:
break;
}
is_stop = (*env)->GetBooleanField(env, obj, stop_id);
}
close(fd);
和类似的java代码
@Override
public boolean onTouchEvent(MotionEvent event) {
float x = event.getRawY();
float y = event.getRawX();
Log.i(TAG, "x = " + x + " y = " + y);
if (marker != null) {
int xy[] = marker.getLocation();
Log.i(TAG, "rawx = " + xy[0] + " rawy = " + xy[1]);
}
// the rawx != x and rawy != y ,how to convert?
return super.onTouchEvent(event);
}
有人可以帮忙吗?