Our smartphones are capable of some impressive processing power, quickly replacing much of what we used the desktop PC for, in the past: mainly document management and communication. But there's always a balance between functionality and security, and Google's Android decided to opt mostly in favor of the latter, leaving out critical functionality on purpose, such as injecting keys or touch events to a third party process.
While this seems unimportant to the regular user, this is fundamentally crucial for developing "also regular" applications such as: remote administration (like VNC, teamviewer, remote control), for application test tools, or for applications aiming to improve the smartphone control for persons with disabilities (using the chair joystick to control the Android phone). Another example here, is the option to create a custom mouse pointer on top of your Android screen, for application control purposes, as presented here, that also needs to be able to inject the touch events when the user clicks.
Not to mention various automation tasks, hacks & mods but in the end is all about the freedom given to the development community. The Android platform makers should come up with some better solutions.
header_android_inject_events

Introduction

In part 1 of this article I have indicated three ways of injecting events on the Android platform:
Method 1: Using internal APIs, mainly relying on the WindowManager and the two APIs: injectPointerEvent and injectKeyEvent

Method 2: Using an instrumentation object

Method 3: Direct event injection to /dev/input/eventX

While the first two rely on the dreaded INJECT_EVENTS permission, available only to platform makers, and have suffered great changes in the last OS versions, the third method is at the moment of writing this article the best bet for properly injecting events on Android.

The /dev/input/eventX are event input nodes, part of the linux platform beneath Android. Normally their permissions are set so only the Owner and its Group can read and write from/top these files. There are no permissions set for Other, and there is where our code is situated, since it is not owner of the linux input event nodes, nor member of the Owner group:
android_input_event_nodes

So to be able to use method 3, and to directly interface to the input event nodes, we need to be able to alter the permissions, in order to set the Other permission bit to Read (if we want to intercept input event data) or Write (if we want to push events, as indicated in the article's title: Injecting events). The best way to go is to set the bit to allow +rw (read and write) , using the chmod native command:
android_input_event_nodes_chmod
Without root access, this fails, with "operation not permitted". So here is the point where we can only proceed if we are using a Rooted Android phone. Everything else shown in this article will work without root, but for changing the permissions we need root, and there's no way around it. A bit frustrating, considering we are talking about such a tiny information segment. More on linux filesystem permissions, here.

Once the input event nodes are set to allow both reading and writing, we can open them as regular files, and read the content or write our own content, to intercept events or inject our own keys or touch events. The format accepted by the input event node files is:

  1. struct input_event {
  2. struct timeval time;
  3. unsigned short type;
  4. unsigned short code;
  5. unsigned int value;
  6. };
  7. /* type and code are values defined in linux/input.h.
  8.  * For example, type might be EV_REL for relative moment of a mouse,
  9.  * or EV_KEY for a keypress, and code is the keycode, or REL_X or ABS_X for a mouse.
  10.  * The linux/input.h is part of the Android NDK
  11.  */

Make sure to read more on this topic, for a better understanding. A nice article is available on Linux Journal.

By popular demand on my two previous articles: Programmatically Injecting Events on Android – Part 1 and Android Overlay Mouse Cursor, but also to standardize method #3, I have developed a JNI library for Android, to take care of all these details to do what the standard API refuses to do: simple event injection for all your development needs. But it requires root, as explained previously.

The library, named "android-event-injector" is released as Open Source, under GPL, and available on Google code, here.

Android Event Injector functionality

android_inject_touch_key_event_diagram This library uses JNI, and you will need to setup Android NDK if you want to change it or compile it.

It uses a low level, native component, that completely handles the input event node interaction: discovering the files (ScanFiles), opening them (OpenDev), Closing/Removing allocated memory (RemoveDev) or getting event node details such as Path and Name. With an open Input Event Node, we can do polling (PollDev, getType, getCode, getValue) or event injection (intSendEvent).

Via JNI, we are handling all this functionality in Java (Events.Java). This class builds multiple instances of the InputDevice class, that correspond to the number of discovered native input event nodes (the number of /dev/input/eventX files). When we open such a file, we use the API call Open(boolean forceOpen):

  1.  
  2. /**
  3. * function Open : opens an input event node
  4. * @param forceOpen will try to set permissions and then reopen if first open attempt fails
  5. * @return true if input event node has been opened
  6. */
  7. public boolean Open(boolean forceOpen) {
  8. int res = OpenDev(m_nId);
  9. // if opening fails, we might not have the correct permissions, try changing 660 to 666
  10. if (res != 0) {
  11. // possible only if we have root
  12. if(forceOpen && Shell.isSuAvailable()) {
  13. // set new permissions
  14. Shell.runCommand("chmod 666 "+ m_szPath);
  15. // reopen
  16. res = OpenDev(m_nId);
  17. }
  18. }
  19. m_szName = getDevName(m_nId);
  20. m_bOpen = (res == 0);
  21. // debug
  22. Log.d(LT, "Open:"+m_szPath+" Name:"+m_szName+" Result:"+m_bOpen);
  23. // done, return
  24. return m_bOpen;
  25. }
  26.  

As you can see, at this point we also use chmod to make sure our process can read and write the input event node (/dev/input/eventX file).

If we are successful in opening an event node, we can use it for listening for events (system touch events, key presses, etc), or for injecting events. The code on Google code, exemplifies all these:

Listening for incoming events

Here is a simple example on how to use my library, to create a thread that intercepts all system input events and shows them in logcat:

  1.  
  2. /**
  3. * Starts our event monitor thread that does the data extraction via polling
  4. * all data is displayed in the textview, as type-code-value, see input.h in the Android NDK for more details
  5. * Monitor output is also sent to Logcat, so make sure you used that as well
  6. */
  7. public void StartEventMonitor() {
  8. m_bMonitorOn = true;
  9. Thread b = new Thread(new Runnable() {
  10. public void run() {
  11. while (m_bMonitorOn) {
  12. for (InputDevice idev:events.m_Devs) {
  13. // Open more devices to see their messages
  14. if (idev.getOpen() && (0 == idev.getPollingEvent())) {
  15. final String line = idev.getName()+
  16. ":" + idev.getSuccessfulPollingType()+
  17. " " + idev.getSuccessfulPollingCode() +
  18. " " + idev.getSuccessfulPollingValue();
  19. Log.d(LT, "Event:"+line);
  20. // update textview to show data
  21. //if (idev.getSuccessfulPollingValue() != 0)
  22. m_tvMonitor.post(new Runnable() {
  23. public void run() {
  24. m_tvMonitor.setText(line);
  25. }
  26. });
  27. }
  28. }
  29. }
  30. }
  31. });
  32. b.start();
  33. }
  34.  

This is very useful when you need to better understand the event structure and the involved values for type,code and value. Make sure you have a look on linux/input.h contents as well, inside your Android NDK folder.

Injecting events

Again, input.h is our friend, since it details the event codes we need to use. But you will also want to use the event monitor to be able to write down all the complex events sequence generated by the system when the user touches the screen. Here are a few wrapper functions to serve as a sample:
Home hardware key injection:

  1.  
  2. /**
  3. * Finds an open device that has a name containing keypad. This probably is the event node associated with the keypad
  4. * Its purpose is to handle all hardware Android buttons such as Back, Home, Volume, etc
  5. * Key codes are defined in input.h (see NDK) , or use the Event Monitor to see keypad messages
  6. * This function sends the HOME key
  7. */
  8. public void SendHomeKeyToKeypad() {
  9. boolean found = false;
  10. for (InputDevice idev:events.m_Devs) {
  11. //* Finds an open device that has a name containing keypad. This probably is the keypad associated event node
  12. if (idev.getOpen() && idev.getName().contains("keypad")) {
  13. idev.SendKey(102, true); // home key down
  14. idev.SendKey(102, false); // home key up
  15. found = true; break;
  16. }
  17. }
  18. if (found == false)
  19. Toast.makeText(this, "Keypad not found.", Toast.LENGTH_SHORT).show();
  20. }
  21.  

And another example, for injecting touch events:

  1. //absolute coordinates, on my device they go up to 570x960
  2. if (m_selectedDev!=-1)
  3. events.m_Devs.get(m_selectedDev).SendTouchDownAbs(155,183);
  4.  

Don't forget to correctly use the Event input devices. When you open them, you also have access to the Device Name. Make sure you insert key events to the device named "keypad" or "keyboard" and not to the compass or other input devices if you want this to work. Also for touch events, make sure you insert your touches/click events to "touchpad" or "ts". The namings can be different from a device to another, or from a platform to another. Try to develop an algorithm to correctly identify your target before injecting input data.

android_inject_keys_touches_4 android_inject_keys_touches_3 android_inject_keys_touches_2 android_inject_keys_touches_1

Additional resources:

Programmatically Injecting Events on Android – Part 1
Android Overlay Mouse Cursor
The code is available on Google Code, under GPL. Use it only if you understand the terms of Open Source software distributed under GPL.
The library and a sample can be downloaded here or EventInjector

(Visited 2,633 times, 1 visits today)
facebooktwittergoogle_plusredditpinterestlinkedinmailfacebooktwittergoogle_plusredditpinterestlinkedinmail
Tagged on:                                                 

83 thoughts on “Programmatically Injecting Events on Android – Part 2

  • July 27, 2013 at 6:19 pm
    Permalink

    @Aakar: I had the same issue and imported my own input.h version containing all the missing declarations.

  • September 6, 2013 at 8:18 pm
    Permalink

    Thanks for this very helpful article.
    I do have a problem with your suggestion of changing the permissions on the /dev/event* device files: any other app (whether granted root or not) has full access to these files (well, until the next reboot).

    Why not run a small service binary (owned by root, chmod 500) to access /dev/input* and communicate with the app which want to inject events?
    Have the app (which the user needs to grant root access) start and stop this service. This should reduces the risk of some random app hijacking your touchscreen to plunder your bank account, etc.

  • September 6, 2013 at 10:58 pm
    Permalink

    Hi Alain,

    Thanks for your suggestion; the purpose of this article was demonstrating the input event functionality and not the security issues. Would love to handle everything very much like you have described but time is not my friend.

    Others can build upon my work and take care of the remaining issues, the source code is open source.

  • September 11, 2013 at 11:58 am
    Permalink

    Thanks for the great article.

    I’m facing the same problem as Aakar and i can’t get it to work. It is the first time i am working with ndk so if you could give me a hand on what to do?

    I tried importing the input.h as suggested but i keep having a lot erros due to undeclared values…

    Should i just declare the variables myself?
    Sorry if it is a simple question and thanks in advanced.

  • September 11, 2013 at 12:27 pm
    Permalink

    Apparently posting the question was all i need to resolve most of my issues.
    Had one version of the input.h which did not contained all i needed.

    Thank you anyway.

  • September 11, 2013 at 1:28 pm
    Permalink

    @Andre, great to see you found what you needed.

  • September 11, 2013 at 10:42 pm
    Permalink

    I implemented the project, changed the sendkey function Alessandro told us (41) but im still not able to inject key events. Im using a galaxy nexus with androd 4.3. Any suggestions?

    Thanks already

  • September 12, 2013 at 2:45 pm
    Permalink

    @Mart, have you been able to see where the problem is? Any specific errors you are getting?

  • September 18, 2013 at 10:38 am
    Permalink

    Hello @Motisan, thank you very much for your great post which helps me much.But I have one question, how can we detect which device in /dev/input/eventX represents the touchpad and which represents the keypad?I’ve tried catting /proc/bus/input/handlers to find out something, but it doesn’t work.It still can’t detect which means what from the name properties.Is there any exact method?Thank you for your help!

  • October 3, 2013 at 5:16 pm
    Permalink

    Hello again,

    I’m trying to do what @Alessandro suggested “create a virtual device with uinput and forward events”.

    I’m finding difficult to do the proper setup for the virtual device to be a touch screen. I am hopping someone here can point me in the right direction…

    This is what i’ve got,

    fd = open(“/dev/uinput”, O_WRONLY | O_NONBLOCK);
    if (fd < 0) {
    die("error: open");
    }
    if(ioctl(fd, UI_SET_KEYBIT, BTN_TOUCH) < 0)
    die("error: ioctl");

    if(ioctl(fd, UI_SET_EVBIT, EV_ABS) < 0)
    die("error: ioctl");
    if(ioctl(fd, UI_SET_RELBIT, ABS_X) < 0)
    die("error: ioctl");
    if(ioctl(fd, UI_SET_RELBIT, ABS_X) < 0)
    die("error: ioctl");

    memset(&uidev, 0, sizeof(uidev));
    snprintf(uidev.name, UINPUT_MAX_NAME_SIZE, "uinput-sample");
    uidev.id.bustype = BUS_USB;
    uidev.id.vendor = 0x1;
    uidev.id.product = 0x1;
    uidev.id.version = 1;

    if (write(fd, &uidev, sizeof(uidev)) < 0) {
    die("error: write");
    }

    if (ioctl(fd, UI_DEV_CREATE) < 0) {
    die("error: ioctl");
    }

    Thank you for your time.

  • October 3, 2013 at 5:53 pm
    Permalink

    After i create the device it is automaticly removed and i have no idea why.

    Removing device ‘/dev/input/event6′ due to inotify event

  • October 3, 2013 at 6:28 pm
    Permalink

    Sorry for the spam but ignore the last post, it has nothing to do with that.

  • October 4, 2013 at 3:12 am
    Permalink

    I’m currently developing a device which reads external information(such as motion) and convert it to touch motion in Android.(For Wearable Computer Competition 2013)
    Thankfully, due to your work, I could realize such device.
    However, I’m currently in trouble.

    Although the injection do work for key, touch injection work only partially.
    Without pressing the screen(at least in the corner), the injected touch(which is given continuously) is NOT injected at all.
    (adb getevent doesn’t show any event injected, although the LogCat (using intEnableDebug) shows that the function intSendEvent is done.

    The intSendEvent I sent per (injected) touch is the following.

    intSendEvent(m_fd, EV_ABS,57,29);
    intSendEvent(m_fd, 3, 53,x);
    intSendEvent(m_fd, 3, 54,y);
    intSendEvent(m_fd, 3, 48,100);
    intSendEvent(m_fd, EV_ABS, 58,2);
    intSendEvent(m_fd,0,0,0);
    intSendEvent(m_fd,3,57,0xffffff);
    intSendEvent(m_fd,0,0,0);
    (Ah, EV_ABS=3)
    (In my case, m_fd is /dev/input/event2 for touchscreen)

    Also, for unknown reason, without modifying the JNI C line into
    void Java_(…)intSendEvent( JNIEnv* env,jobject thiz, int fd_kb, uint16_t type, uint16_t code, uint16_t value)
    (changed value’s type from int32_t to uint16_t)
    the value is fixed to 0.

    Do you have any possible idea why such problems arise?
    In my opinion,
    1(and Worst). The phone manufacturer had set another mechanism which prevents Android to recognize changes in /dev/input/eventX without really activating touchscreen.
    2. I set the sequence of events very very wrong.(Much better though :) )

    The device I currently use is
    Galaxy S4 LTE-A (SHV-E330S in Korea but probably similar to GT-i9506 (same spec)).

    Thank you for reading this ^^
    and Sorry for my bad english.
    Ps. I emailed this but I decided to repost this whether your email address is correct. Sorry :(

  • October 4, 2013 at 8:34 am
    Permalink

    @Hyeongkeun kim: I have also implemented a “monitor” function exactly for the kind of problems you ran into: start it, and then tap the screen to see what messages are being generated. You will then need to repeat the process from your code, but using the SendEvent api. This should be easy.

  • October 4, 2013 at 6:39 pm
    Permalink

    Is the monitor function equivalent to looking at data output from
    Adb shell getevent (-l) | grep /dev/input/event2?

  • Pingback: C, Android NDK: import own input.h version containing missing declarations | Technology & Programming Answers

  • November 20, 2013 at 1:04 am
    Permalink

    Hello Radu, these two part articule is great, after reading carefully i have only one question:
    How can i translate from a MotionEvent and create an event using your api with all the basic data of a MotionEvent?
    In others works how to translate every value from a MotionEvent object into values that inject the correct event using your api?
    Can you give me some tips?
    The scene i have is an app that catch events in an android movil terminal and transmit those values to other android terminal in MotionEvent format, so in this last terminal i need to inject the received events.

    Thank you very much,
    Maykell.

  • November 29, 2013 at 10:35 am
    Permalink

    Hi,Thanks you work for open source.

    Hi,Recently, My team need to do some record and replay feature on the phone, i found you project.
    the link was : https://code.google.com/p/android-event-injector/

    I have a problem.

    I using InputDev to collect all the touch events. But why not replay by using intSendEvent?

  • November 29, 2013 at 10:54 am
    Permalink

    Maykell, you might want to check out the source of MotionEvent in the Android open source, for that.

    Eric, is your phone rooted?

  • December 3, 2013 at 10:24 am
    Permalink

    Hi,Thanks your job for this project.I just using cygwin to compile you jni code, but fail,Most of the error was happen in the EventInjector.h ,Do u have something code forgot to commit to googleCode?

  • December 3, 2013 at 10:36 am
    Permalink

    $ /cygdrive/e/NDK/android-ndk-r8e/ndk-build
    Cygwin : Generating dependency file converter script
    Compile thumb : EventInjector <= EventInjector.c
    In file included from E:/soft/jni/EventInjector.c:55:0:
    E:/soft/jni/EventInjector.h:43:9: error: 'INPUT_PROP_POINTER' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:44:9: error: 'INPUT_PROP_DIRECT' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:45:9: error: 'INPUT_PROP_BUTTONPAD' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:46:9: error: 'INPUT_PROP_SEMI_MT' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:69:9: error: 'SYN_MT_REPORT' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:69:9: error: initializer element is not constant
    E:/soft/jni/EventInjector.h:69:9: error: (near initialization for 'syn_labels[2].value')
    E:/soft/jni/EventInjector.h:70:9: error: 'SYN_DROPPED' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:70:9: error: initializer element is not constant
    E:/soft/jni/EventInjector.h:615:9: error: initializer element is not constant
    E:/soft/jni/EventInjector.h:615:9: error: (near initialization for 'abs_labels[26].value')
    E:/soft/jni/EventInjector.h:718:9: error: (near initialization for 'mt_tool_labels[0].value')
    E:/soft/jni/EventInjector.h:719:9: error: 'MT_TOOL_PEN' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:719:9: error: initializer element is not constant
    E:/soft/jni/EventInjector.h:719:9: error: (near initialization for 'mt_tool_labels[1].value')
    E:/soft/jni/EventInjector.h:720:9: error: 'MT_TOOL_MAX' undeclared here (not in a function)
    E:/soft/jni/EventInjector.h:720:9: error: initializer element is not constant
    E:/soft/jni/EventInjector.h:720:9: error: (near initialization for 'mt_tool_labels[2].value')
    /cygdrive/e/NDK/android-ndk-r8e/build/core/build-binary.mk:269: recipe for target `/cygdrive/e/soft/obj/local/armeabi/objs/EventInjector/EventInjector.o' failed
    make: *** [/cygdrive/e/soft/obj/local/armeabi/objs/EventInjector/EventInjector.o] Error 1
    zhangkai@zhangkai-PC /cygdrive/e/soft/jni
    $ cd d:
    zhangkai@zhangkai-PC /cygdrive/d
    $ cd ttt
    zhangkai@zhangkai-PC /cygdrive/d/ttt
    $ cd jni
    zhangkai@zhangkai-PC /cygdrive/d/ttt/jni
    $ /cygdrive/e/NDK/android-ndk-r8e/ndk-build
    /cygdrive/e/NDK/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in /cygdrive/d/ttt/AndroidManifest.xml
    /cygdrive/d/ttt/obj/local/armeabi/objs/EventInjector/EventInjector.o.d:1: *** STOP
    zhangkai@zhangkai-PC /cygdrive/d/ttt/jni
    $ /cygdrive/e/NDK/android-ndk-r8e/ndk-build
    /cygdrive/e/NDK/android-ndk-r8e/build/core/add-application.mk:128: Android NDK: WARNING: APP_PLATFORM android-14 is larger than android:minSdkVersion 8 in /cygdrive/d/ttt/AndroidManifest.xml
    Cygwin : Generating dependency file converter script
    Compile thumb : EventInjector <= EventInjector.c
    In file included from D:/ttt/jni/EventInjector.c:55:0:
    D:/ttt/jni/EventInjector.h:43:9: error: 'INPUT_PROP_POINTER' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:44:9: error: 'INPUT_PROP_DIRECT' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:45:9: error: 'INPUT_PROP_BUTTONPAD' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:46:9: error: 'INPUT_PROP_SEMI_MT' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:69:9: error: 'SYN_MT_REPORT' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:69:9: error: initializer element is not constant
    D:/ttt/jni/EventInjector.h:69:9: error: (near initialization for 'syn_labels[2].value')
    D:/ttt/jni/EventInjector.h:70:9: error: 'SYN_DROPPED' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:70:9: error: initializer element is not constant
    D:/ttt/jni/EventInjector.h:70:9: error: (near initialization for 'syn_labels[3].value')
    D:/ttt/jni/EventInjector.h:194:9: error: 'KEY_SCALE' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:194:9: error: initializer element is not constant
    D:/ttt/jni/EventInjector.h:194:9: error: (near initialization for 'key_labels[119].value')
    D:/ttt/jni/EventInjector.h:228:9: error: 'KEY_SCREENLOCK' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:228:9: error: initializer element is not constant
    D:/ttt/jni/EventInjector.h:228:9: error: (near initialization for 'key_labels[153].value')
    D:/ttt/jni/EventInjector.h:275:9: error: 'KEY_DASHBOARD' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:275:9: error: initializer element is not constant
    D:/ttt/jni/EventInjector.h:275:9: error: (near initialization for 'key_labels[200].value')
    D:/ttt/jni/EventInjector.h:308:9: error: 'KEY_BLUETOOTH' undeclared here (not in a function)
    D:/ttt/jni/EventInjector.h:720:9: error: (near initialization for 'mt_tool_labels[2].value')
    /cygdrive/e/NDK/android-ndk-r8e/build/core/build-binary.mk:269: recipe for target `/cygdrive/d/ttt/obj/local/armeabi/objs/EventInjector/EventInjector.o' failed
    make: *** [/cygdrive/d/ttt/obj/local/armeabi/objs/EventInjector/EventInjector.o] Error 1

  • December 19, 2013 at 9:44 am
    Permalink

    Hi
    first at all sorry for my english
    Radu, thank you for your library
    I am trying to send touch event.
    Here are log from adb getevent
    +—————————————-
    /dev/input/event1: 0003 0035 0000015b
    /dev/input/event1: 0003 0036 0000012f
    /dev/input/event1: 0000 0000 00000000
    /dev/input/event1: 0003 0039 ffffffff -touch up
    /dev/input/event1: 0000 0000 00000000
    +—————————————-

    and from Eclipse logcat
    +—————————————-
    Event:ct36x_ts:3 53 347
    Event:ct36x_ts:3 54 303
    Event:ct36x_ts:0 0 0
    Event:ct36x_ts:3 57 -1 -touch up
    Event:ct36x_ts:0 0 0
    +————————————-

    I mofifyed “SendTouchDownAbs” according with my options

    +————————————————————–
    public int SendTouchDownAbs(int x, int y ) {
    intSendEvent(m_nId, EV_ABS, 53, x);
    intSendEvent(m_nId, EV_ABS, 54, y);
    intSendEvent(m_nId, 0, 0, 0);
    intSendEvent(m_nId, EV_ABS, 57, -1); //touch up
    intSendEvent(m_nId, 0, 0, 0);
    return 1;
    }
    +————————————————————–

    but it works only for touch down, no touch up (release) and the log gives only
    +————————————————————–
    /dev/input/event1: 0003 0035 0000015b
    /dev/input/event1: 0003 0036 0000012f
    /dev/input/event1: 0000 0000 00000000
    +————————————————————–
    without the relese comands

    As you can see the action touch up (release) has a -1 or 0xffffffff. I tried both of them. If I put 0 insteaad “-1″ the log gives
    +—————————————-
    /dev/input/event1: 0003 0035 0000015b
    /dev/input/event1: 0003 0036 0000012f
    /dev/input/event1: 0000 0000 00000000
    /dev/input/event1: 0003 0039 00000000
    /dev/input/event1: 0000 0000 00000000
    +—————————————-
    but there is still no touch up (release).

    Can you help me with it?
    Thank you

  • December 19, 2013 at 10:24 am
    Permalink

    Hi Igor,

    There’s been some time since I wrote this, and do not remember all the details, but what you should do is to use the Event Monitor function, included in the sample I’ve provided. First carefully analyze all the messages (similar to what you posted: getevent/eclipse log), then try to inject exactly the same sequences.

    If you managed to get it working for touch down, it will work for touch up as well, just get the sequence right.

  • December 19, 2013 at 11:24 am
    Permalink

    Hi,
    why the sequence are different in getevent “0003 0039 ffffffff” and in eclipse log “3 57 -1″? I mean the last value “0xffffffff” and “-1″. I have tried to use both of them in my function with no effect.

  • December 19, 2013 at 12:49 pm
    Permalink

    that might be because of the unsigned/signed integer conversion.

  • February 12, 2014 at 11:01 pm
    Permalink

    Hi Radu, is there any way to normalize the codes injected so we could write a an event injector that works with all devices ?
    I mean, are the differences caused by devices (hardware) or android versions ?
    If it’s just android version , it would be easy to implement it , but the other way is out of reach.

  • February 12, 2014 at 11:06 pm
    Permalink

    Hi Walker,

    Most likely yes, but I didn’t have the time to look into it.

  • February 19, 2014 at 2:29 pm
    Permalink

    Hi

    Big fan of this lib. I’ve used and extended it for many devices, but have now stumbled into a question that I cannot sovle without some feedback.

    Some webpages utilize mouse hover effects and I would like to be able to inject such events to a Android WebView. I obviously cannot do this using the touch injection of this lib since there is no such thing as ‘hover touch’ on android. But I am guessing that it is possible somehow since a cursor appears if I connect a mouse to a Android tablet and the hover effect happens in the WebView if I hover this mouse cursor over affected areas.

    Any idea how to use your lib for injecting mouse hover/movement events?

    BTW, I’ve tried ‘opening’ the mouse Input Devs on a few devices with no success. So I am unable to get any useful output.

    Thx in advance.

  • April 15, 2014 at 5:29 am
    Permalink

    Hi Radu,
    Any idea how to use your lib for touch events without external devices.
    Thank you in advance.

  • August 15, 2014 at 1:28 am
    Permalink

    Hi Radu,

    I’m facing a problem with this library on my Samsung Galaxy S4. Chmod of the event works but still it fails to write anything to a particular event.

    Seems like an issue due to KNOX. On other devices it works. Can you please help me solve the issue? Your help will be highly appreciated.

    Thanks.

  • November 20, 2014 at 1:12 pm
    Permalink

    In which file have you included the EventMonitor?

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>