Table Of Contents
Motion Event¶
The MotionEvent is the base class used for every touch and non-touch event. This class defines all the properties and methods needed to handle 2D and 3D movements but has many more capabilities.
Note
You never create the MotionEvent yourself: this is the role of the providers.
Motion Event and Touch¶
We differentiate between a Motion Event and Touch event. A Touch event is a MotionEvent with the pos profile. Only theses events are dispatched throughout the widget tree.
The MotionEvent ‘s are gathered from input providers.
- All the MotionEvent ‘s are dispatched from
- If a MotionEvent has a pos profile, we dispatch it through
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)
Profiles¶
A capability is the ability of a MotionEvent to store new information or a way to indicate what is supported by the MotionEvent. For example, you can receive a MotionEvent that has an angle, a fiducial ID, or even a shape. You can check the profile attribute to check what is currently supported by the MotionEvent and how to access it.
This is a tiny list of the supported profiles by default. Check other input providers to see if there are other profiles available.
Profile name | Description |
angle | 2D angle. Use property a |
button | Mouse button (left, right, middle, scrollup, scrolldown) Use property button |
markerid | Marker or Fiducial ID. Use property fid |
pos | 2D position. Use properties x, y or pos` |
pos3d | 3D position. Use properties x, y, z |
pressure | Pressure of the contact. Use property pressure |
shape | Contact shape. Use property shape |
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
- class kivy.input.motionevent.MotionEvent(device, id, args)[source]¶
Bases: kivy.input.motionevent.MotionEvent
Abstract class to represent a touch and non-touch object.
Parameters: - id : str
unique ID of the MotionEvent
- args : list
list of parameters, passed to the depack() function
- apply_transform_2d(transform)[source]¶
Apply a transformation on x, y, z, px, py, pz, ox, oy, oz, dx, dy, dz
- device = None¶
Device used for creating this touch
- double_tap_time = None¶
If the touch is a is_double_tap, this is the time between the previous tap and the current touch.
- dpos[source]¶
Return delta between last position and current position, in the screen coordinate system (self.dx, self.dy)
- dsx = None¶
Delta between self.sx and self.psx, in 0-1 range.
- dsy = None¶
Delta between self.sy and self.psy, in 0-1 range.
- dsz = None¶
Delta between self.sz and self.psz, in 0-1 range.
- dx = None¶
Delta between self.x and self.px, in window range
- dy = None¶
Delta between self.y and self.py, in window range
- dz = None¶
Delta between self.z and self.pz, in window range
- grab(class_instance, exclusive=False)[source]¶
Grab this motion event. You can grab a touch if you absolutly want to receive on_touch_move() and on_touch_up(), even if the touch is not dispatched by your parent:
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
- grab_current = None¶
Used to determine which widget the touch is being dispatched to. Check the grab() function for more information.
- id = None¶
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 uid attribute instead.
- is_double_tap = None¶
Indicate if the touch is a double tap or not
- is_mouse_scrolling[source]¶
Returns True if the touch is a mousewheel scrolling
New in version 1.6.0.
- is_triple_tap = None¶
Indicate if the touch is a triple tap or not
New in version 1.7.0.
- opos[source]¶
Return the initial position of the touch in the screen coordinate system (self.ox, self.oy)
- osx = None¶
Origin X position, in 0-1 range.
- osy = None¶
Origin Y position, in 0-1 range.
- osz = None¶
Origin Z position, in 0-1 range.
- ox = None¶
Origin X position, in window range
- oy = None¶
Origin Y position, in window range
- oz = None¶
Origin Z position, in window range
- pos = None¶
Position (X, Y), in window range
- ppos[source]¶
Return the previous position of the touch in the screen coordinate system (self.px, self.py)
- profile = None¶
Profiles currently used in the touch
- psx = None¶
Previous X position, in 0-1 range.
- psy = None¶
Previous Y position, in 0-1 range.
- psz = None¶
Previous Z position, in 0-1 range.
- push_attrs_stack = None¶
Attributes to push by default, when we use push() : x, y, z, dx, dy, dz, ox, oy, oz, px, py, pz.
- px = None¶
Previous X position, in window range
- py = None¶
Previous Y position, in window range
- pz = None¶
Previous Z position, in window range
- sx = None¶
X position, in 0-1 range
- sy = None¶
Y position, in 0-1 range
- sz = None¶
Z position, in 0-1 range
- time_end = None¶
Time of the end event (last touch usage)
- time_start = None¶
Initial time of the touch creation
- time_update = None¶
Time of the last update
- triple_tap_time = None¶
If the touch is a is_triple_tap, this is the time between the first tap and the current touch. .. versionadded:: 1.7.0
- ud = None¶
User data dictionary. Use this dictionary to save your own data on the touch.
- uid = None¶
Uniq ID of the touch. You can safely use this property, it will be never the same accross all existing touches.
- x = None¶
X position, in window range
- y = None¶
Y position, in window range
- z = None¶
Z position, in window range