Getting the coordinates from the location I touch the touchscreen

In a UIResponder subclass, such as UIView: override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.anyObject()! as UITouch let location = touch.locationInView(self) } This will return a CGPoint in view coordinates. Updated with Swift 3 syntax override func touchesBegan(touches: NSSet, withEvent event: UIEvent) { let touch = touches.first! let location = touch.location(in: … Read more

Get the co-ordinates of a touch event on Android

You can use this function : http://developer.android.com/reference/android/view/View.html#setOnTouchListener(android.view.View.OnTouchListener) You will probably put it in your onCreate method roughly this way (tested this time) : Activity onCreate code @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); final TextView textView = (TextView)findViewById(R.id.textView); // this is the view on which you will listen for touch events final View touchView … Read more

JavaScript mapping touch events to mouse events

I am sure this is what you want: function touchHandler(event) { var touches = event.changedTouches, first = touches[0], type = “”; switch(event.type) { case “touchstart”: type = “mousedown”; break; case “touchmove”: type = “mousemove”; break; case “touchend”: type = “mouseup”; break; default: return; } // initMouseEvent(type, canBubble, cancelable, view, clickCount, // screenX, screenY, clientX, clientY, … Read more

Detecting a long press in Android

GestureDetector is the best solution. Here is an interesting alternative. In onTouchEvent on every ACTION_DOWN schedule a Runnable to run in 1 second. On every ACTION_UP or ACTION_MOVE, cancel scheduled Runnable. If cancelation happens less than 1s from ACTION_DOWN event, Runnable won’t run. final Handler handler = new Handler(); Runnable mLongPressed = new Runnable() { … Read more