// E/JniUtils(11823): couldn't get gazeEventFromNative, (FFZZLandroid/app/Activity;)V private static void gazeEventFromNative(float x, float y, bool press, bool release, Activity target) { Log.d(TAG, "gazeEventFromNative( " + x + " " + y + " " + press + " " + release + " " + target); (new Handler(Looper.getMainLooper())).post( new xRunnable() { yield = delegate { long now = SystemClock.uptimeMillis(); if (press) { downTime = now; } MotionEvent.PointerProperties pp = new MotionEvent.PointerProperties(); pp.toolType = MotionEvent.TOOL_TYPE_FINGER; pp.id = 0; MotionEvent.PointerProperties[] ppa = new MotionEvent.PointerProperties[1]; ppa[0] = pp; MotionEvent.PointerCoords pc = new MotionEvent.PointerCoords(); pc.x = x; pc.y = y; MotionEvent.PointerCoords[] pca = new MotionEvent.PointerCoords[1]; pca[0] = pc; int eventType = MotionEvent.ACTION_MOVE; if (press) { eventType = MotionEvent.ACTION_DOWN; } else if (release) { eventType = MotionEvent.ACTION_UP; } MotionEvent ev = MotionEvent.obtain( downTime, now, eventType, 1, ppa, pca, 0, /* meta state */ 0, /* button state */ 1.0f, 1.0f, /* precision */ 10, /* device ID */ 0, /* edgeFlags */ InputDevice.SOURCE_TOUCHSCREEN, 0 /* flags */); Log.d(TAG, "Synthetic:" + ev); Window w = target.getWindow(); View v = w.getDecorView(); v.dispatchTouchEvent(ev); } }); }
void SendMotionEvent(int action, MouseEventArgs e) { long time = android.os.SystemClock.uptimeMillis(); if (action == MotionEvent.ACTION_DOWN) { mouse_down = time; } else if (mouse_down == 0) { return; } using (MotionEvent me = MotionEvent.obtain(mouse_down, time, action, e.X, e.Y, 0)) XobotActivityManager.Invoke((window) => window.SendMotionEvent(me)); if (action == MotionEvent.ACTION_UP) { mouse_down = 0; } }