Skip to main content

tiny hotkey library based on python-evdev

Project description


Pyzmo is a small hotkey library for Python 2.7+ based on python-evdev. It has support for keys, key chords (simultaneously pressed keys) and key sequences (keys pressed in succession).


from pyzmo import *
from evdev.ecodes import *

# triggered when KEY_PLAYPAUSE is pressed
def playpause(events):

# triggered when KEY_B is pressed, held or released
@key(KEY_B, states=['down', 'hold', 'up'])
def back(events):

# triggered when either KEY_C or KEY_D are pressed
@key(KEY_C, KEY_D)
def c_or_d(events):

# triggered when KEY_LEFTCTRL, KEY_LEFTALT and KEY_DELETE are
# pressed at the same time
def ctrlaltdel(events):

# triggered when KEY_A, KEY_B and KEY_C are pressed one after the other
@keyseq(KEY_A, KEY_B, KEY_C)
def abc(events):

# specifying multiple sequences for one callback (syntax applies for
# @chord and @event as well)
@keyseq( (KEY_1, KEY_2, KEY_3), (KEY_Z, KEY_X, KEY_C) )
def zxc_or_123(events):

# each handler receives the list of input events, because of
# which it was triggered
@chord(e.KEY_LEFTMETA, e.KEY_A)
def term(events):
    for event in events:
        print(event)  # instance of
        #event at 1352244701.749908, code 125, type 01, val 01
        #event at 1352244701.861897, code 30, type 01, val 01

## Note 1:
# If we define two triggers:
#  - @chord(KEY_LEFTCTRL, KEY_V)
#  - @key(KEY_V)
# Pressing 'ctrl-v' will run both their callbacks. To stop
# processing any further triggers after a match is made, use:
@chord(KEY_LEFTCTRL, KEY_V, quick=True)
def copy(events):

## Note 2:
# Pyzmo can actually match arbitrary input events. The following
# will be triggered on scroll-wheel movement:
@event(EV_REL, REL_WHEEL, -1)
def vertical_scroll(events):

# start main loop
poll('/dev/input/event1', '/dev/input/event2')

# .. or if you wish to get exclusive access to a input device
from evdev import InputDevice
dev = InputDevice('/dev/input/eventX')

You can avoid polluting the global namespace with:

from pyzmo import EventHandler
from evdev import ecodes as e

app = EventHandler('name')

def f(events): pass



The latest stable version of pyzmo is available on pypi, while the development version can be installed from github:

$ pip install pyzmo  # latest stable version
$ pip install git+git://  # latest development version

Alternatively, you can install it manually like any other python package:

$ git clone
$ cd pyzmo
$ git reset --hard HEAD $versiontag
$ python install

Similar Projects


Pyzmo is released under the terms of the New BSD License.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pyzmo-0.1.0.tar.gz (5.8 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page