-
-
Save dieterplex/93f674a9b11fc47279994bd76b2506a6 to your computer and use it in GitHub Desktop.
Export key type counts from Niz Plum 68. Reference: https://github.com/cho45/niz-tools-ruby/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# using python-hidapi | |
import hid | |
import time | |
VENDOR_ID = 0x0483 | |
PRODUCT_ID = 0x5032 | |
TOTAL_KEY_COUNT = 68 | |
h = hid.device() | |
keyboard_path = [ a['path'] for a in hid.enumerate(VENDOR_ID, PRODUCT_ID) if a['interface_number']==1][0] | |
h.open_path(keyboard_path) | |
# https://github.com/cho45/niz-tools-ruby/blob/71075ee0ef2a1e609dd40c4610b433e7afcf8aa1/niz.rb#L296 | |
HWCODE = { | |
0 : '', # unmapped value | |
1 : 'ESC', | |
2 : 'F1', | |
3 : 'F2', | |
4 : 'F3', | |
5 : 'F4', | |
6 : 'F5', | |
7 : 'F6', | |
8 : 'F7', | |
9 : 'F8', | |
10 : 'F9', | |
11 : 'F10', | |
12 : 'F11', | |
13 : 'F12', | |
14 : '`', | |
15 : '1', | |
16 : '2', | |
17 : '3', | |
18 : '4', | |
19 : '5', | |
20 : '6', | |
21 : '7', | |
22 : '8', | |
23 : '9', | |
24 : '0', | |
25 : '-', | |
26 : '=', | |
27 : 'BS', | |
28 : 'TAB', | |
29 : 'Q', | |
30 : 'W', | |
31 : 'E', | |
32 : 'R', | |
33 : 'T', | |
34 : 'Y', | |
35 : 'U', | |
36 : 'I', | |
37 : 'O', | |
38 : 'P', | |
39 : '[', | |
40 : ']', | |
41 : '\\', | |
42 : 'Caps Lock', | |
43 : 'A', | |
44 : 'S', | |
45 : 'D', | |
46 : 'F', | |
47 : 'G', | |
48 : 'H', | |
49 : 'J', | |
50 : 'K', | |
51 : 'L', | |
52 : ';', | |
53 : '\'', | |
54 : 'RET', | |
55 : 'L-Shift', | |
56 : 'Z', | |
57 : 'X', | |
58 : 'C', | |
59 : 'V', | |
60 : 'B', | |
61 : 'N', | |
62 : 'M', | |
63 : ',', | |
64 : '.', | |
65 : '/', | |
66 : 'R-Shift', | |
67 : 'L-CTRL', | |
68 : 'Left-Super', | |
69 : 'L-Alt', | |
70 : 'Space', | |
71 : 'R-Alt', | |
72 : 'Right-Super', | |
73 : 'ContextMenu', | |
74 : 'R-Ctrl', | |
75 : 'Wakeup', | |
76 : 'Sleep', | |
77 : 'Power', | |
78 : 'PriSc', | |
79 : 'SclLk', | |
80 : 'Pause', | |
81 : 'Ins', | |
82 : 'Home', | |
83 : 'PageUp', | |
84 : 'Del', | |
85 : 'End', | |
86 : 'PageDown', | |
87 : 'Up Arrow', | |
88 : 'Left Arrow', | |
89 : 'Down Arrow', | |
90 : 'Right Arrow', | |
91 : 'Num Lock', | |
92 : '(/)', | |
93 : '(*)', | |
94 : '(7)', | |
95 : '(8)', | |
96 : '(9)', | |
97 : '(4)', | |
98 : '(5)', | |
99 : '(6)', | |
100 :'(1)', | |
101 :'(2)', | |
102 :'(3)', | |
103 :'(0)', | |
104 :'(.)', | |
105 :'(-)', | |
106 :'(+)', | |
107 :'(Enter)', | |
108 : 'Media Next Track', | |
109 : 'Media Previous Track', | |
110 : 'Media Stop', | |
111 : 'Media Play/Pause', | |
112 : 'Media Mute', | |
113 : 'Media VolumeUp', | |
114 : 'Media VolumeDn', | |
115 : 'Media Select', | |
116 : 'WWW Email', | |
117 : 'Media Calculator', | |
118 : 'Media My Computer', | |
119 : 'WWW Search', | |
120 : 'WWW Home', | |
121 : 'WWW Back', | |
122 : 'WWW Forward', | |
123 : 'WWW Stop', | |
124 : 'WWW Refresh', | |
125 : 'WWW Favorites', | |
126 : 'Mouse Mouse Left', | |
127 : 'Mouse Mouse Right', | |
128 : 'Mouse Mouse Up', | |
129 : 'Mouse Mouse Down', | |
130 : 'Mouse Key Left', | |
131 : 'Mouse Key Right', | |
132 : 'Mouse Key Middle', | |
133 : 'Mouse Wheel Up', | |
134 : 'Mouse Wheel Dn', | |
135 : 'Backlight Switch', | |
136 : 'Backlight Macro', | |
137 : 'Demonstrate', | |
138 : 'Star shower', | |
139 : 'Riffle', | |
140 : 'Demo Stop', | |
141 : 'Breathe', | |
142 : 'Breathe Sequence-', | |
143 : 'Breathe Sequence+', | |
144 : 'Backlight Lightness-', | |
145 : 'Backlight Lightness+', | |
146 : 'Sunset or Relax/Aurora', | |
147 : 'Color Breathe', | |
148 : 'Back Color Exchange', | |
149 : 'Adjust Trigger Point', | |
150 : 'Keyboard Lock', | |
151 : 'Shift&Up', | |
152 : 'Ctrl&Caps Exchange', | |
153 : 'WinLock', | |
154 : 'MouseLock', | |
155 : 'Win/Mac Exchange', | |
156 : 'R-Fn', | |
157 : 'Mouse Unit Pixel', | |
158 : 'Mouse Unit Time', | |
159 : 'Programmable keyboard', | |
160 : 'Backlight Record1', | |
161 : 'Backlight Record2', | |
162 : 'Backlight Record3', | |
163 : 'Backlight Record4', | |
164 : 'Backlight Record5', | |
165 : 'Backlight Record6', | |
166 : 'L-Fn', | |
167 : 'Wire/Wireless exchange', | |
168 : 'BTD1', | |
169 : 'BTD2', | |
170 : 'BTD3', | |
171 : 'Game', | |
172 : 'ECO', | |
173 : 'Mouse First Delay', | |
174 : 'Key Repeat Rate', | |
175 : 'Key Response Delay', | |
176 : 'USB Report Rate', | |
177 : 'Key Scan Period', | |
178 : 'unknown', | |
179 : 'unknown', | |
180 : 'unknown', | |
181 : 'unknown', | |
182 : 'unknown', | |
183 : 'unknown', | |
184 : 'unknown', | |
185 : 'unknown', | |
186 : 'unknown', | |
187 : 'unknown', | |
188 : 'unknown', | |
189 : 'unknown', | |
190 : 'unknown', | |
191 : 'unknown', | |
192 : 'unknown', | |
193 : 'unknown', | |
194 : 'unknown', | |
195 : 'unknown', | |
196 : 'unknown', | |
197 : 'unknown', | |
198 : 'unknown', | |
199 : 'Mouse Left Double Click', | |
200 : 'unknown', | |
201 : 'unknown', | |
202 : 'unknown', | |
203 : 'unknown', | |
204 : '<>|', | |
205 : 'unknown', | |
206 : 'unknown', | |
207 : 'unknown', | |
208 : 'unknown', | |
209 : 'unknown', | |
210 : 'unknown', | |
211 : 'unknown', | |
212 : 'unknown', | |
213 : 'unknown', | |
214 : 'unknown', | |
215 : 'unknown', | |
216 : 'unknown', | |
217 : 'unknown', | |
218 : 'unknown', | |
219 : 'unknown', | |
220 : 'unknown', | |
221 : 'unknown', | |
222 : 'unknown', | |
223 : 'unknown', | |
224 : 'unknown', | |
225 : 'unknown', | |
226 : 'unknown', | |
227 : 'unknown', | |
228 : 'unknown', | |
229 : 'unknown', | |
230 : 'unknown', | |
231 : 'unknown', | |
232 : 'unknown', | |
233 : 'unknown', | |
234 : 'unknown', | |
235 : 'unknown', | |
236 : 'unknown', | |
237 : 'unknown', | |
238 : 'unknown', | |
239 : 'unknown', | |
240 : 'unknown', | |
241 : 'unknown', | |
242 : 'unknown', | |
243 : 'unknown', | |
244 : 'unknown', | |
245 : 'unknown', | |
246 : 'unknown', | |
247 : 'unknown', | |
248 : 'unknown', | |
249 : 'unknown', | |
250 : 'unknown', | |
251 : 'unknown', | |
252 : 'unknown', | |
253 : 'unknown', | |
254 : 'unknown', | |
255 : 'unknown', | |
} | |
COMMAND_READ_COUNTER = 0xe3 | |
COMMAND_READ_ALL = 0xf2 | |
def send_command(command, data=b""): | |
send_data = [0] * 65 | |
send_data[0] = 0x00 # report_id | |
send_data[2] = command | |
send_data[3:min(len(data), 62)+3] = list(data) | |
return h.write(send_data) | |
def read_counter(): | |
all_counts = [] | |
res = send_command(COMMAND_READ_COUNTER) | |
while True: | |
get_data = h.read(64) | |
if get_data[0] != 0: | |
break | |
for i in range(3, len(get_data) - 1, 4): | |
all_counts.append(int.from_bytes(bytes(get_data[i:(i+4)]), 'little')) | |
return all_counts | |
def read_keymaps(): | |
keymaps = [[0,0,0,0,0,0] for i in range(TOTAL_KEY_COUNT)] | |
res = send_command(COMMAND_READ_ALL) | |
while True: | |
get_data = h.read(64) | |
#print(get_data) | |
if get_data[0] != 0: | |
break | |
level = get_data[2] - 1 | |
key_id = get_data[3] - 1 | |
hwcode = get_data[6] | |
keymaps[key_id][level] = hwcode | |
return keymaps | |
cnts = read_counter() | |
keymaps = read_keymaps() | |
res = ([(i+1 , tuple([HWCODE[a] for a in keymaps[i]]),cnts[i]) for i in range(66)]) | |
ascii_keys = sum([ e[2] for i, e in enumerate(res) if len(e[1][0]) == 1]) | |
enter_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'RET']) | |
bs_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'BS']) | |
space_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'Space']) | |
shift_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'L-Shift']) | |
ctrl_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'L-CTRL']) | |
tab_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'TAB']) | |
esc_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'ESC']) | |
cmd_key = sum([ e[2] for i, e in enumerate(res) if e[1][0] == 'Left-Super']) | |
all_key = sum([e[2] for i, e in enumerate(res)]) | |
import datetime | |
print({ | |
"TIME": datetime.datetime.now().isoformat(), | |
"ASCII": ascii_keys, | |
"ENTER": enter_key, | |
"BS": bs_key, | |
"SP": space_key, | |
"Shift": shift_key, | |
"Ctrl": ctrl_key, | |
"TAB": tab_key, | |
"ESC": esc_key, | |
"Cmd": cmd_key, | |
"SUM": all_key | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment