2

I'm try to inject event on an android device without touchscreen. I'm using user space input device (uinput) to do so but it doesn't work.

I'm using this code:

fd_virtual_dev = open("/dev/uinput", O_WRONLY | O_NONBLOCK);
if (fd_virtual_dev < 0)
    return die("error: open");

if (ioctl(fd_virtual_dev, UI_SET_EVBIT, EV_ABS) < 0)
    return die("error: ioctl ev_abs");
if (ioctl(fd_virtual_dev, UI_SET_EVBIT, EV_SYN) < 0)
    return die("error: ioctl ev_syn");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_TOUCH_M AJOR) < 0)
    return die("error: ioctl ABS_MT_TOUCH_MAJOR");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_WIDTH_M AJOR) < 0)
    return die("error: ioctl ABS_MT_TOUCH_MAJOR");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_POSITIO N_X) < 0)
    return die("error: ioctl ABS_MT_POSITION_X");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_POSITIO N_Y) < 0)
    return die("error: ioctl ABS_MT_POSITION_Y");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_TRACKIN G_ID) < 0)
    return die("error: ioctl ABS_MT_TRACKING_ID");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_SLOT) < 0)
    return die("error: ioctl");
if (ioctl(fd_virtual_dev,UI_SET_ABSBIT,ABS_MT_PRESSUR E) < 0)
    return die("error: ioctl ABS_MT_PRESSURE");

memset(&uidev, 0, sizeof(uidev));
snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-device");
uidev.id.bustype = BUS_VIRTUAL;
uidev.id.vendor = 0x0;
uidev.id.product = 0x0;
uidev.id.version = 0;    
uidev.absmax[ABS_MT_TOUCH_MAJOR] = 64;
uidev.absmax[ABS_MT_WIDTH_MAJOR] = 64;
uidev.absmax[ABS_MT_POSITION_X] = 1024;
uidev.absmax[ABS_MT_POSITION_Y] = 800;
uidev.absmax[ABS_MT_TRACKING_ID] = 65535;
uidev.absmax[ABS_MT_SLOT] = 9;
uidev.absmax[ABS_MT_PRESSURE] = 64;

Now, if I try to sende multitouch protocolo B events I can see only a little circle on the screen in an pseduorandom point

I'v tried also with protocoll A and on a touchscreen phone with the same result Alfonso

2
  • Have you solve your problem? I am also looking for a way to create multitouch devices use uinput as yours,but I can't even create a single touch. so I want get some help from you.
    – ccc
    Dec 17, 2013 at 5:57
  • No! I could not find any valid solutions Dec 28, 2013 at 12:20

2 Answers 2

2

If UI_SET_PROPBIT is NOT defined in the header file 'uinput.h' you are including, add below line:

#define UI_SET_PROPBIT    _IOW(UINPUT_IOCTL_BASE, 110, int)

before the line:

ioctl(uinput_fd, UI_SET_PROPBIT, INPUT_PROP_DIRECT)

I tested it on Nexus7. The touch event works well except it cannot apply on the Android system virtual buttons (BACK, HOME and RECENT) which is a different problem.

1

Try adding the following ioctl call:

ioctl(dev_file, UI_SET_PROPBIT, INPUT_PROP_DIRECT)

If that doesn't work you'll need to add an IDC file (as described here) for the product and vendor IDs you've specified, under /system/usr/idc. In your case it would be /system/usr/idc/Vendor_0000_Product_0000.idc, though consider using unique product/vendor values.

The IDC file should specify that the device is a touch screen: touch.deviceType = touchScreen

Without an IDC file, the device is likely being identified as a mouse, which results in the little circle. If you're building a custom Android image, you can drop the IDC file in the Android source tree under /out/target/product/<product>/system/usr/idc. Otherwise try uploading the IDC via "adb shell".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.