python/buttonmap.py (raw)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
from input import Pointer def set(map): """Set your buttonmap. Functions in the button map should all take a single argument, a Client object, except for functions for Action_Motion events, who should take 2 arguments, a PointerData object and a Client object.""" global _press_map, _release_map, _click_map, _doubleclick_map, _motion_map Pointer.clearBinds() _press_map = [] _release_map = [] _click_map = [] _doubleclick_map = [] _motion_map = [] for button, context, action, func in map: if (action == Pointer.Action_Press): _press_map.append((button, context, func)) mapfunc = press_run if (action == Pointer.Action_Release): _release_map.append((button, context, func)) mapfunc = release_run if (action == Pointer.Action_Click): _click_map.append((button, context, func)) mapfunc = click_run if (action == Pointer.Action_DoubleClick): _doubleclick_map.append((button, context, func)) mapfunc = doubleclick_run if (action == Pointer.Action_Motion): _motion_map.append((button, context, func)) mapfunc = motion_run Pointer.bind(button, context, action, mapfunc) def press_run(ptrdata, client): """Run a button press event through the buttonmap""" button = ptrdata.button context = ptrdata.context for but, cont, func in _press_map: if (but == button and cont == context): func(client) def release_run(ptrdata, client): """Run a button release event through the buttonmap""" button = ptrdata.button context = ptrdata.context for but, cont, func in _release_map: if (but == button and cont == context): func(client) def click_run(ptrdata, client): """Run a button click event through the buttonmap""" button = ptrdata.button context = ptrdata.context for but, cont, func in _click_map: if (but == button and cont == context): func(client) def doubleclick_run(ptrdata, client): """Run a button doubleclick event through the buttonmap""" button = ptrdata.button context = ptrdata.context for but, cont, func in _doubleclick_map: if (but == button and cont == context): func(client) def motion_run(ptrdata, client): """Run a pointer motion event through the buttonmap""" button = ptrdata.button context = ptrdata.context for but, cont, func in _motion_map: if (but == button and cont == context): func(ptrdata, client) _press_map = () _release_map = () _click_map = () _doubleclick_map = () _motion_map = () |