MotionEvent is the base class used for events provided by
pointing devices (touch and non-touch). This class defines all the properties
and methods needed to handle 2D and 3D movements but has many more
Motion Event and Touch¶
We differentiate between a Motion Event and Touch event. A Touch event is a
MotionEvent with the pos profile. Only these events are dispatched
throughout the widget tree.
Listening to a Motion Event¶
If you want to receive all MotionEvents, Touch or not, you can bind the
MotionEvent from the
Window to your own callback:
def on_motion(self, etype, motionevent): # will receive all motion events. pass Window.bind(on_motion=on_motion)
You can also listen to changes of the mouse position by watching
MotionEvent stores device specific information in various
properties listed in the
For example, you can receive a MotionEvent that has an angle, a fiducial
ID, or even a shape. You can check the
attribute to see what is currently supported by the MotionEvent provider.
This is a short list of the profile values supported by default. Please check
MotionEvent.profile property to see what profile values are
|angle||2D angle. Accessed via the a property.|
|button||Mouse button (‘left’, ‘right’, ‘middle’, ‘scrollup’ or ‘scrolldown’). Accessed via the button property.|
|markerid||Marker or Fiducial ID. Accessed via the fid property.|
|pos||2D position. Accessed via the x, y or pos properties.|
|pos3d||3D position. Accessed via the x, y or z properties.|
|pressure||Pressure of the contact. Accessed via the pressure property.|
|shape||Contact shape. Accessed via the shape property .|
If you want to know whether the current
MotionEvent has an angle:
def on_touch_move(self, touch): if 'angle' in touch.profile: print('The touch angle is', touch.a)
If you want to select only the fiducials:
def on_touch_move(self, touch): if 'markerid' not in touch.profile: return
MotionEvent(device, id, args)¶
Abstract class that represents an input event (touch or non-touch).
- id: str
unique ID of the MotionEvent
- args: list
list of parameters, passed to the depack() function
Apply a transformation on x, y, z, px, py, pz, ox, oy, oz, dx, dy, dz
Copy some attribute to another touch object.
Depack args into attributes of the class
Device used for creating this touch
Return the distance between the current touch and another touch.
If the touch is a
is_double_tap, this is the time between the previous tap and the current touch.
Return delta between last position and current position, in the screen coordinate system (self.dx, self.dy)
Delta between self.sx and self.psx, in 0-1 range.
Delta between self.sy and self.psy, in 0-1 range.
Delta between self.sz and self.psz, in 0-1 range.
Delta between self.x and self.px, in window range
Delta between self.y and self.py, in window range
Delta between self.z and self.pz, in window range
def on_touch_down(self, touch): touch.grab(self) def on_touch_move(self, touch): if touch.grab_current is self: # I received my grabbed touch else: # it's a normal touch def on_touch_up(self, touch): if touch.grab_current is self: # I receive my grabbed touch, I must ungrab it! touch.ungrab(self) else: # it's a normal touch pass
Used to determine which widget the touch is being dispatched to. Check the
grab()function for more information.
Id of the touch, not uniq. This is generally the Id set by the input provider, like ID in TUIO. If you have multiple TUIO source, the same id can be used. Prefer to use
Indicate if the touch is a double tap or not
Returns True if the touch is a mousewheel scrolling
New in version 1.6.0.
Indicate if the touch is a triple tap or not
New in version 1.7.0.
Move the touch to another position
Return the initial position of the touch in the screen coordinate system (self.ox, self.oy)
Origin X position, in 0-1 range.
Origin Y position, in 0-1 range.
Origin Z position, in 0-1 range.
Origin X position, in window range
Origin Y position, in window range
Origin Z position, in window range
Pop attributes values from the stack
Position (X, Y), in window range
Return the previous position of the touch in the screen coordinate system (self.px, self.py)
Profiles currently used in the touch
Previous X position, in 0-1 range.
Previous Y position, in 0-1 range.
Previous Z position, in 0-1 range.
Push attribute values in attrs onto the stack
Attributes to push by default, when we use
push(): x, y, z, dx, dy, dz, ox, oy, oz, px, py, pz.
Previous X position, in window range
Previous Y position, in window range
Previous Z position, in window range
scale_for_screen(w, h, p=None, rotation=0, smode='None', kheight=0)¶
Scale position for the screen
Return the position in the 0-1 coordinate system (self.sx, self.sy)
X position, in 0-1 range
Y position, in 0-1 range
Z position, in 0-1 range
Time of the end event (last touch usage)
Initial time of the touch creation
Time of the last update
If the touch is a
is_triple_tap, this is the time between the first tap and the current touch.
New in version 1.7.0.
User data dictionary. Use this dictionary to save your own data on the touch.
Uniq ID of the touch. You can safely use this property, it will be never the same accross all existing touches.
Ungrab a previously grabbed touch
X position, in window range
Y position, in window range
Z position, in window range