-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremap_nostromo_for_factorio.py
111 lines (91 loc) · 2.84 KB
/
remap_nostromo_for_factorio.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import asyncio
import logging
from macronizer.consts.input_event_codes import EventType, KeyEventCode
from macronizer.device.uinput_device import UInputDevice
from macronizer.device_config.razer import RazerNostromo
from macronizer.pipeline.pipeline import DestNode, SourceNode
from macronizer.pipeline.remapper import RemapConfig, Remapper
logging.basicConfig(level=logging.DEBUG)
Code = RazerNostromo.KeyCode
modifiers = [
Code.KEY_LEFT,
Code.KEY_DOWN,
]
KEY_SHIFT = KeyEventCode.KEY_LEFTSHIFT
KEY_CTRL = KeyEventCode.KEY_LEFTCTRL
rules = {
(): {
Code.KEY_01: KeyEventCode.KEY_ESC,
Code.KEY_02: KeyEventCode.KEY_Q,
Code.KEY_03: KeyEventCode.KEY_W,
Code.KEY_04: KeyEventCode.KEY_E,
Code.KEY_05: KeyEventCode.KEY_R,
Code.KEY_06: KEY_SHIFT,
Code.KEY_07: KeyEventCode.KEY_A,
Code.KEY_08: KeyEventCode.KEY_S,
Code.KEY_09: KeyEventCode.KEY_D,
Code.KEY_10: KeyEventCode.BTN_RIGHT,
Code.KEY_11: KeyEventCode.KEY_ENTER,
Code.KEY_12: KeyEventCode.KEY_T,
Code.KEY_13: KeyEventCode.KEY_F,
Code.KEY_14: KeyEventCode.KEY_TAB,
Code.KEY_15: KeyEventCode.KEY_SPACE,
Code.KEY_UP: KeyEventCode.KEY_Y,
Code.KEY_RIGHT: KeyEventCode.KEY_PAUSE,
Code.KEY_SMALL: KEY_CTRL
},
(Code.KEY_LEFT,): {
Code.KEY_01: KeyEventCode.KEY_1,
Code.KEY_02: KeyEventCode.KEY_2,
Code.KEY_03: KeyEventCode.KEY_3,
Code.KEY_04: KeyEventCode.KEY_4,
Code.KEY_05: KeyEventCode.KEY_5,
Code.KEY_06: KeyEventCode.KEY_KP1,
Code.KEY_07: KeyEventCode.KEY_KP2,
Code.KEY_08: KeyEventCode.KEY_KP3,
Code.KEY_09: KeyEventCode.KEY_KP4,
Code.KEY_10: KeyEventCode.KEY_KP5,
},
(Code.KEY_DOWN,): {
Code.KEY_01: KeyEventCode.KEY_6,
Code.KEY_02: KeyEventCode.KEY_7,
Code.KEY_03: KeyEventCode.KEY_8,
Code.KEY_04: KeyEventCode.KEY_9,
Code.KEY_05: KeyEventCode.KEY_0,
Code.KEY_06: KeyEventCode.KEY_KP6,
Code.KEY_07: KeyEventCode.KEY_KP7,
Code.KEY_08: KeyEventCode.KEY_KP8,
Code.KEY_09: KeyEventCode.KEY_KP9,
Code.KEY_10: KeyEventCode.KEY_KP0,
},
}
def main():
input_device = RazerNostromo.get_input_devices()[0]
source_node = SourceNode([input_device])
config = RemapConfig(modifiers, rules)
remap_node = Remapper(config)
output_device = UInputDevice.create(
support_events={
EventType.EV_KEY: list(config.get_possible_output_keys()),
},
)
dest_node = DestNode(output_device)
source_node.add_subscriber(remap_node)
remap_node.add_subscriber(dest_node)
with input_device.grab(), output_device.open():
loop = asyncio.get_event_loop()
coros = [
source_node.run(loop),
remap_node.run(),
dest_node.run(),
]
for c in coros:
loop.create_task(c)
try:
loop.run_forever()
except KeyboardInterrupt:
pass
finally:
loop.run_until_complete(loop.shutdown_asyncgens())
if __name__ == '__main__':
main()