Input recorder

New in version 1.1.0.

Warning

This part of Kivy is still experimental, and his API is subject to change in a future version.

This is a class that can record and replay some part of input events. This can be used for test case, screen saver etc.

Once activated, the recorder will listen to any input event, and save some properties in a file + the delta time. Later, you can play the input file: it will generate fake touch with saved properties, and dispatch it to the event loop.

By default, only the position are saved (‘pos’ profile and ‘sx’, ‘sy’, attributes). Changes it only if you understand how input is working.

Recording events

The best way is to use the “recorder” module. Check the Modules documentation for learning about how to activate a module.

When activated, you can press F8 to start the recording. By default, events will be written at <currentpath>/recorder.kvi. When you want to stop recording, press F8 again.

You can replay the file by pressing F7.

Check the Recorder module module for more information.

Manual play

You can manually open a recorder file, and play it by doing:

from kivy.input.recorder import Recorder

rec = Recorder(filename='myrecorder.kvi')
rec.play = True

If you want to loop over that file, you can do:

from kivy.input.recorder import Recorder

def recorder_loop(instance, value):
    if value is False:
        instance.play = True

rec = Recorder(filename='myrecorder.kvi')
rec.bind(play=recorder_loop)
rec.play = True

Recording more attributes

You can extend the attributes to save, at one condition: attributes values must be simple value, not instance of complex class. Aka, saving shape will not work.

Let’s say you want to save angle and pressure of the touch, if available:

from kivy.input.recorder import Recorder

rec = Recorder(filename='myrecorder.kvi',
    record_attrs=['is_touch', 'sx', 'sy', 'angle', 'pressure'],
    record_profile_mask=['pos', 'angle', 'pressure'])
rec.record = True

Or with modules variables:

$ python main.py -m recorder,attrs=is_touch:sx:sy:angle:pressure,            profile_mask=pos:angle:pressure

Known limitations

  • Unable to save attributes with instance of complex class
  • Values that represent time will be not adjusted
  • Can replay only complete record, if a begin/update/end event is missing, this could lead to ghost touch.
  • Stopping the replay before the end can lead to ghost touch.
class kivy.input.recorder.Recorder(**kwargs)

Bases: kivy.event.EventDispatcher

Recorder class, check module documentation for more information.

counter

Number of events recorded in the last session.

counter is a NumericProperty, default to 0, read-only.

filename

Filename to save the output of recorder.

filename is a StringProperty, default to ‘recorder.kvi’.

play

Boolean to start/stop the replay of the current file (if exist.)

play is a BooleanProperty, default to False.

record

Boolean to start/stop the recording of input events.

record is a BooleanProperty, default to False.

record_attrs

Attributes to record from the motion event.

record_attrs is a ListProperty, default to [‘is_touch’, ‘sx’, ‘sy’].

record_profile_mask

Profile to save in the fake motion event when replayed.

record_profile_mask is a ListProperty, default to [‘pos’].

window

Window instance to attach the recorder. If None set, it will use the default one.

window is a ObjectProperty, default to None.