Skip to content. | Skip to navigation

Personal tools
Log in
Sections
You are here: Home Projects Python-uinput examples mouse.py

mouse.py

An example of mouse device and pointer motion moving towards bottom right corner.

mouse.py — Python Source, 0Kb

File contents

#! /usr/bin/env python

import time

import uinput

def main():
    capabilities = {uinput.EV_REL: [uinput.REL_X, uinput.REL_Y],
                    uinput.EV_KEY: [uinput.BTN_LEFT, uinput.BTN_RIGHT],
                    }

    device = uinput.Device(name="python-uinput-mouse",
                           capabilities=capabilities)

    for i in range(20):
        # syn=False for the first call to emit an "atomic" (1, 1)
        # event.
        device.emit(uinput.EV_REL, uinput.REL_X, 5, syn=False)
        device.emit(uinput.EV_REL, uinput.REL_Y, 5)
        time.sleep(0.01) # Just to show the motion.

if __name__ == "__main__":
    main()
Facts
Author: Tuomas Räsänen
License: GPLv3+
Programming languages: Python, C
Source control: Bazaar
Bug control: Launchpad
Support: Launchpad