-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfss.py
executable file
·134 lines (102 loc) · 3.13 KB
/
fss.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#!/usr/bin/env python3
import sys
import getopt
from microdia import FootSwitch, SwitchDef
from Xlib import XK, display
def print_switch(sw):
if sw.type == SwitchDef.STRING:
print("switch %d: string" % sw.num)
elif sw.type == SwitchDef.EVENT:
print("switch %d: event" % sw.num)
bl = ""
ml = ""
if sw.buttonLeft:
bl = "left"
if sw.buttonRight:
if bl != "":
bl += " "
bl += "right"
if sw.buttonMiddle:
if bl != "":
bl += " "
bl += "middle"
if bl == "":
bl = "(none)"
if sw.noLatch:
print(" action: non-latching")
else:
print(" action: latching")
if sw.key != None:
print(" key: %d, raw code: 0x%.2x" % (sw.key, sw.raw_key))
if sw.modCtrlL:
ml = "Ctrl"
if sw.modShift:
if ml == "":
ml += " "
ml += "Shift"
if sw.modAlt:
if ml == "":
ml += " "
ml += "Alt/Option"
if sw.modSuper:
if ml == "":
ml += " "
ml += "Super/Win/Command"
if ml == "":
ml = "(none)"
print(" mod keys: %s" % ml)
print(" mouse buttons: %s" % bl)
print(" mouse movement: x-axis: %d, y-axis: %d, mouse wheel: %d" % (sw.x_move, sw.y_move, sw.mouseWheel))
else:
print("switch %d: not initialized or not present" % sw.num)
def usage():
with open("usage.text", 'r') as usage_f:
for line in usage_f:
print(line, end='')
def main():
reading = True # determins if we're reading or writing, etc.
switch = SwitchDef()
shortopts = "hs:k:lrmx:y:w:"
longopts = ["help", "switch=", "key=", "nolatch"
"ctrl", "shift", "alt", "option", "super", "win", "command",
"left", "right", "middle",
"wheel=",
"string="]
try:
opts, args = getopt.getopt(sys.argv[1:], shortopts, longopts)
except getopt.GetoptError as err:
print(err)
usage()
sys.exit(2)
for opt, arg in opts:
if opt in ("-h", "--help"):
usage()
sys.exit()
elif opt in ("-s", "--switch"):
# TODO check for input sanity
switch.num = int(arg)
elif opt in ("-k", "--key"):
reading = False
try:
switch.key = arg
except ValueError:
print("key »%s« not recognized" % arg)
sys.exit(2)
sw_matrix = FootSwitch()
sw_matrix.open()
print("Device: %s" % sw_matrix.product)
if reading:
if switch.num:
print_switch(sw_matrix.get_switch(switch.num))
else:
for i in range(1, 15):
print_switch(sw_matrix.get_switch(i))
else:
if not switch.num:
print("provide a switch number!")
usage()
sys.exit(2)
sw_matrix.close()
sys.exit(0)
if __name__ == "__main__":
main()