PK q/D/hqK K pyzmo-latest/searchindex.jsSearch.setIndex({envversion:42,terms:{code:0,global:0,becaus:0,syntax:0,held:0,chord:0,zxc_or_123:0,follow:0,simultan:0,key_delet:0,dsl:0,keyseq:0,under:0,leftctrl:0,input:0,main:0,match:0,c_or_d:0,which:0,get:0,pollut:0,evdev:0,stop:0,util:0,ctrlaltdel:0,press:0,requir:0,like:0,term:0,name:0,success:0,arbitrari:0,lisp:0,manual:0,either:0,each:0,quick:0,grab:0,key_playpaus:0,seq:0,key_d:0,list:0,hard:0,back:0,pass:0,further:0,playpaus:0,event:0,librari:0,abc:0,avoid:0,access:0,delet:0,state:0,version:0,sequenc:0,print:0,"import":0,movement:0,altern:0,run:0,kei:0,ev_rel:0,hotkei:0,vertical_scrol:0,small:0,base:0,releas:0,both:0,actual:0,versiontag:0,instanc:0,def:0,com:0,appli:0,app:0,down:0,stabl:0,poll:0,key_leftctrl:0,pyzmo:0,git:0,from:0,val:0,leftalt:0,devic:0,two:0,avail:0,start:0,trigger:0,call:0,actkbd:0,type:0,"function":0,ecod:0,head:0,namespac:0,handler:0,copi:0,specifi:0,eventhandl:0,hold:0,"true":0,reset:0,made:0,wish:0,setup:0,dev:0,rel_wheel:0,defin:0,"while":0,can:0,key_leftmeta:0,embed:0,loop:0,inputdevic:0,ctrl:0,process:0,key_leftalt:0,ani:0,gvalkov:0,packag:0,key_1:0,key_3:0,key_2:0,pip:0,revis:0,multipl:0,inputexec:0,eventi:0,receiv:0,when:0,same:0,note:0,also:0,other:0,eventx:0,you:0,triggerhappi:0,wheel:0,dialect:0,inputev:0,key_f:0,key_a:0,key_c:0,key_b:0,pypi:0,clone:0,after:0,key_v:0,bsd:0,develop:0,respons:0,key_x:0,key_z:0,github:0,well:0,callback:0,time:0,exclus:0,event1:0,event2:0,scroll:0,latest:0},objtypes:{},objnames:{},filenames:["index"],titles:["Introduction"],objects:{},titleterms:{python:0,licens:0,usag:0,project:0,instal:0,similar:0,introduct:0}})PK q/DKn pyzmo-latest/search.html
Pyzmo is a small hotkey library for Python 2.7+ based on python-evdev. It can call arbitrary Python functions in response to key presses, 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
@key(KEY_PLAYPAUSE)
def playpause(events):
pass
# triggered when KEY_B is pressed, held or released
@key(KEY_B, states=['down', 'hold', 'up'])
def back(events):
pass
# triggered when either KEY_C or KEY_D are pressed
@key(KEY_C, KEY_D)
def c_or_d(events):
pass
# triggered when KEY_LEFTCTRL, KEY_LEFTALT and KEY_DELETE are
# pressed at the same time
@chord(KEY_LEFTCTRL, KEY_LEFTALT, KEY_DELETE)
def ctrlaltdel(events):
pass
# 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):
pass
# 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):
pass
# 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 evdev.events.InputEvent
#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):
pass
## 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):
pass
# 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')
dev.grab()
poll(dev)
You can also avoid polluting the global namespace with:
from pyzmo import EventHandler
from evdev import ecodes as e
app = EventHandler('name')
@app.key(e.KEY_F)
def f(events): pass
@app.poll(...)
Pyzmo also has a DSL that can be used from Hy, which is a dialect of lisp that is embedded in Python.
(require pyzmo.dsl)
(import pyzmo [pyzmo [poll util]])
# triggered when KEY_PLAYPAUSE is pressed
(key PLAYPAUSE (print events))
# triggered when KEY_B is pressed, held or released
(key B [:down :hold :up] (print events))
# triggered when either KEY_C or KEY_D are pressed
(key [C D] (print events))
# triggered when KEY_LEFTCTRL, KEY_LEFTALT and KEY_DELETE are
# pressed at the same time
(chord [LEFTCTRL LEFTALT DELETE] (print events))
# triggered when KEY_A, KEY_B and KEY_C are pressed one after the other
(seq [A B C] (print events))
# start main loop
(poll "/dev/input/eventX" "/dev/input/eventY")
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://github.com/gvalkov/pyzmo.git # latest development version
Alternatively, you can install it manually like any other python package:
$ git clone git@github.com:gvalkov/pyzmo.git
$ cd pyzmo
$ git reset --hard HEAD $versiontag
$ python setup.py install
Pyzmo is released under the terms of the Revised BSD License.