Search code examples
gesturekivy

How to record multitouch gestures in Kivy?


I have used the gestures code based on the provided Kivy examples to record and recognize single touch gestures. However, I am not sure how to extend this code to recognize multi-touch gestures. Let's say, for example, a pinch.

My problem becomes specially complicated because I use a laptop with zero multi-touch functionality. How do I combine two single gestures? Is there any example available?


Solution

  • From 1.9.0, Kivy got a multi-touch gesture recognizer integrated: have a look at kivy.multistroke. I personally didn't got time to test it yet.

    If you want to map or act depending of the gesture, you might be interested by the Scatter. Pinch can be done with 2 to N touch, with rotation and translation integrated. You can restrict the transformation to just scale and not rotation / translation. And, when all the touches are released, you could animate the scale to the closest wanted value. You can also set a limit for the minimum scale and maximum scale.

    With few parameters and code, you can pinch to zoom, de/un pinch to unzoom, etc. Maybe that's what you want :) (like pinch to zoom in a image, or put an image in fullscreen).

    You can also just use the Scatter's scale parameters, or Scale's matrix to do your own things :)