c - Android mouse cursor event /dev/uinput not moving on Y axis -
i'm trying move cursor mouse on android using /dev/uinput , ioctl.
here code :
int fd = -1; struct input_event ev; int uinput_open_device() { fd = open("/dev/uinput", o_wronly | o_nonblock); if (fd < 0) { __android_log_print(android_log_debug, "code c", "failed open event"); return -1; } return fd; } int dev_uinput_init_mouse(char *name) { struct uinput_user_dev dev; fd = uinput_open_device(); if (fd > 0) { ioctl(fd, ui_set_evbit, ev_key); ioctl(fd, ui_set_keybit, btn_left); ioctl(fd, ui_set_evbit, ev_rel); ioctl(fd, ui_set_relbit, rel_x); ioctl(fd, ui_set_relbit, rel_y); memset(&dev, 0, sizeof(dev)); strncpy(dev.name, name, uinput_max_name_size); dev.id.bustype = bus_usb; dev.id.vendor = 0x1; dev.id.product = 0x1; dev.id.version = 1; if (write(fd, &dev, sizeof(dev)) < 0) { __android_log_print(android_log_debug, "code c", "failed write"); close(fd); } if (ioctl(fd, ui_dev_create) < 0) { __android_log_print(android_log_debug, "ioctl", "create failed..."); close(fd); return -1; } } return fd; void dev_uinput_sync(int fd) { memset(&ev, 0, sizeof(struct input_event)); ev.type = ev_syn; ev.code = syn_report; ev.value = 0; if (write(fd, &ev, sizeof(struct input_event)) < 0) { __android_log_print(android_log_debug, "code c", "failed write"); } else { __android_log_print(android_log_debug, "code c", "sync ok !"); } } void ptr_abs(int fd, int x, int y) { memset(&ev, 0, sizeof(struct input_event)); ev.type = ev_rel; ev.code = rel_x; ev.value = x; write(fd, &ev, sizeof(struct input_event)) memset(&ev, 0, sizeof(struct input_event)); ev.type = ev_rel; ev.code = rel_y; ev.value = y; write(fd, &ev, sizeof(struct input_event); dev_uinput_sync(fd); } void dev_uinput_close(int fd) { ioctl(fd, ui_dev_destroy); close(fd); } jniexport void jnicall java_com_example_hellojni_hellojni_mousesimulation(jnienv *env, jobject instance, jint absx, jint absy) { ptr_abs(fd, absx, absy); } jniexport void jnicall java_com_example_hellojni_hellojni_openfd(jnienv *env, jobject instance) { dev_uinput_init_mouse("uinput-sample-test"); } jniexport void jnicall java_com_example_hellojni_hellojni_closefd(jnienv *env, jobject instance) { dev_uinput_close(fd); }
all these functions called through service in android application. function java_com_example_hellojni_hellojni_mousesimulation(int xaxis, int yaxis)
called value xaxis , yaxis on screen can see mouse moving on x axis , not on y axis.
for example, if call java_com_example_hellojni_hellojni_mousesimulation(200, 100)
cursor move 200 pixels on x axis , nothing on y axis.
as can see movement executed function void ptr_abs(int fd, int x, int y)
the write
on function not fail. enabled movement on y axis using ioctl
on rel_y
function.
i'm compiling code on android api 19.
thank !
the problem solved... removed every __android_log_print , condition in every write function , works...
strange...
Comments
Post a Comment