-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmacro_launcher.py
executable file
·64 lines (49 loc) · 1.74 KB
/
macro_launcher.py
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
#!/usr/bin/python
import json
from evdev import InputDevice, categorize, ecodes
from subprocess import Popen
import sys
import os
import asyncio
import pdb
async def run_macro(device, macros):
while True:
async for event in device.async_read_loop():
if event.type == ecodes.EV_KEY:
if event.value == 1:
k = str(event.code-1)
if debug:
print("Keypress captured: {}".format(k))
if macros.get(k, False):
if debug:
print("Macro being executed: {}".format(macros[k]))
Popen(macros[k], shell=True)
config_path = os.path.join(os.getenv("HOME"), ".macros/config.json")
if len(sys.argv) == 2:
debug = True
else:
debug = False
devices = os.listdir('/dev/input/by-id/')
macros = json.loads(open(config_path).read())
mice = [os.path.join('/dev/input/by-id/',d) for d in devices if d in macros.keys()]
# pdb.set_trace()
if len(mice) == 0:
print("No mouse devices with configured profiles found. :(")
sys.exit(1)
devices = [[InputDevice(m), macros[m.split('/')[-1]]] for m in mice]
for device, m in devices:
device.grab()
# pdb.set_trace()
asyncio.ensure_future(run_macro(device, m))
loop = asyncio.get_event_loop()
loop.run_forever()
# for event in device.read_loop():
# if event.type == ecodes.EV_KEY:
# if event.value == 1:
# k = str(event.code-1)
# if debug:
# print("Keypress captured: {}".format(k))
# if macros.get(k, False):
# if debug:
# print("Macro being executed: {}".format(macros[k]))
# Popen(macros[k], shell=True)