You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

465 lines
22 KiB

  1. from functools import reduce
  2. import re
  3. strings = []
  4. number_of_strings = -1
  5. def top_level_split(s):
  6. """
  7. Split `s` by top-level commas only. Commas within parentheses are ignored.
  8. """
  9. # Parse the string tracking whether the current character is within
  10. # parentheses.
  11. balance = 0
  12. parts = []
  13. part = ""
  14. for i in range(len(s)):
  15. c = s[i]
  16. part += c
  17. if c == '(':
  18. balance += 1
  19. elif c == ')':
  20. balance -= 1
  21. elif c == ',' and balance == 0 and not s[i+1] == ',':
  22. part = part[:-1].strip()
  23. parts.append(part)
  24. part = ""
  25. # Capture last part
  26. if len(part):
  27. parts.append(part.strip())
  28. return parts
  29. def new_chord(on_pseudolayer, keycodes_hash, has_counter, value1, value2, function, output_buffer, index):
  30. counter_link = "NULL"
  31. output_buffer += "uint8_t state_" + str(index) + " = IDLE;\n"
  32. if has_counter:
  33. output_buffer += "uint8_t counter_" + str(index) + " = 0;\n"
  34. counter_link = "&counter_" + str(index)
  35. output_buffer += "const struct Chord chord_" + str(index) + " PROGMEM = {" + keycodes_hash + ", " + on_pseudolayer + ", &state_" + str(index) + ", " + counter_link + ", " + str(value1) + ", " + str(value2) + ", " + function + "};\n"
  36. index += 1
  37. return [output_buffer, index]
  38. def KC(on_pseudolayer, keycodes_hash, keycode, output_buffer, index):
  39. return new_chord(on_pseudolayer, keycodes_hash, False, keycode, 0, "single_dance", output_buffer, index)
  40. def AS(on_pseudolayer, keycodes_hash, keycode, output_buffer, index):
  41. return new_chord(on_pseudolayer, keycodes_hash, True, keycode, 0, "autoshift_dance", output_buffer, index)
  42. def AT(on_pseudolayer, keycodes_hash, output_buffer, index):
  43. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "autoshift_toggle", output_buffer, index)
  44. def KL(on_pseudolayer, keycodes_hash, keycode, to_pseudolayer, output_buffer, index):
  45. return new_chord(on_pseudolayer, keycodes_hash, True, keycode, to_pseudolayer, "key_layer_dance", output_buffer, index)
  46. def KK(on_pseudolayer, keycodes_hash, keycode1, keycode2, output_buffer, index):
  47. return new_chord(on_pseudolayer, keycodes_hash, True, keycode1, keycode2, "key_key_dance", output_buffer, index)
  48. def KM(on_pseudolayer, keycodes_hash, keycode, to_pseudolayer, output_buffer, index):
  49. return new_chord(on_pseudolayer, keycodes_hash, False, keycode, to_pseudolayer, "key_mod_dance", output_buffer, index)
  50. def MO(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index):
  51. return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "temp_pseudolayer", output_buffer, index)
  52. def MO_alt(on_pseudolayer, keycodes_hash, from_pseudolayer, to_pseudolayer, output_buffer, index):
  53. return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, from_pseudolayer, "temp_pseudolayer_alt", output_buffer, index)
  54. def LOCK(on_pseudolayer, keycodes_hash, output_buffer, index):
  55. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "lock", output_buffer, index)
  56. def DF(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index):
  57. return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "perm_pseudolayer", output_buffer, index)
  58. def TO(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index):
  59. return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "switch_layer", output_buffer, index)
  60. def OSK(on_pseudolayer, keycodes_hash, keycode, output_buffer, index):
  61. return new_chord(on_pseudolayer, keycodes_hash, False, keycode, 0, "one_shot_key", output_buffer, index)
  62. def OSL(on_pseudolayer, keycodes_hash, to_pseudolayer, output_buffer, index):
  63. return new_chord(on_pseudolayer, keycodes_hash, False, to_pseudolayer, 0, "one_shot_layer", output_buffer, index)
  64. def CMD(on_pseudolayer, keycodes_hash, output_buffer, index):
  65. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "command", output_buffer, index)
  66. def DM_RECORD(on_pseudolayer, keycodes_hash, output_buffer, index):
  67. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_record", output_buffer, index)
  68. def DM_NEXT(on_pseudolayer, keycodes_hash, output_buffer, index):
  69. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_next", output_buffer, index)
  70. def DM_END(on_pseudolayer, keycodes_hash, output_buffer, index):
  71. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_end", output_buffer, index)
  72. def DM_PLAY(on_pseudolayer, keycodes_hash, output_buffer, index):
  73. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "dynamic_macro_play", output_buffer, index)
  74. def LEAD(on_pseudolayer, keycodes_hash, output_buffer, index):
  75. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "leader", output_buffer, index)
  76. def CLEAR(on_pseudolayer, keycodes_hash, output_buffer, index):
  77. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "clear", output_buffer, index)
  78. def RESET(on_pseudolayer, keycodes_hash, output_buffer, index):
  79. return new_chord(on_pseudolayer, keycodes_hash, False, 0, 0, "reset", output_buffer, index)
  80. def STR(on_pseudolayer, keycodes_hash, string_input, output_buffer, index, number_of_strings, strings):
  81. [a, b] = new_chord(on_pseudolayer, keycodes_hash, False, number_of_strings, 0, "string_in", output_buffer, index)
  82. return [a, b, number_of_strings + 1, strings + [string_input]]
  83. def M(on_pseudolayer, keycodes_hash, value1, value2, fnc, output_buffer, index):
  84. return new_chord(on_pseudolayer, keycodes_hash, True, value1, value2, fnc, output_buffer, index)
  85. def expand_keycode_fnc(DEFINITION):
  86. if DEFINITION == "`":
  87. DEFINITION = "GRAVE"
  88. elif DEFINITION == "-":
  89. DEFINITION = "MINUS"
  90. elif DEFINITION == "=":
  91. DEFINITION = "EQUAL"
  92. elif DEFINITION == "[":
  93. DEFINITION = "LBRACKET"
  94. elif DEFINITION == "]":
  95. DEFINITION = "RBRACKET"
  96. elif DEFINITION == "\\":
  97. DEFINITION = "BSLASH"
  98. elif DEFINITION == ";":
  99. DEFINITION = "SCOLON"
  100. elif DEFINITION == "'":
  101. DEFINITION = "QUOTE"
  102. elif DEFINITION == ",":
  103. DEFINITION = "COMMA"
  104. elif DEFINITION == ".":
  105. DEFINITION = "DOT"
  106. elif DEFINITION == "/":
  107. DEFINITION = "SLASH"
  108. elif DEFINITION == "~":
  109. DEFINITION = "TILDE"
  110. elif DEFINITION == "*":
  111. DEFINITION = "ASTERISK"
  112. elif DEFINITION == "+":
  113. DEFINITION = "PLUS"
  114. elif DEFINITION == "(":
  115. DEFINITION = "LEFT_PAREN"
  116. elif DEFINITION == ")":
  117. DEFINITION = "RIGHT_PAREN"
  118. elif DEFINITION == "<":
  119. DEFINITION = "LEFT_ANGLE_BRACKET"
  120. elif DEFINITION == ">":
  121. DEFINITION = "RIGHT_ANGLE_BRACKET"
  122. elif DEFINITION == "{":
  123. DEFINITION = "LEFT_CURLY_BRACE"
  124. elif DEFINITION == "}":
  125. DEFINITION = "RIGHT_CURLY_BRACE"
  126. elif DEFINITION == "?":
  127. DEFINITION = "QUESTION"
  128. elif DEFINITION == "~":
  129. DEFINITION = "TILDE"
  130. elif DEFINITION == ":":
  131. DEFINITION = "COLON"
  132. elif DEFINITION == "_":
  133. DEFINITION = "UNDERSCORE"
  134. elif DEFINITION == '"':
  135. DEFINITION = "DOUBLE_QUOTE"
  136. elif DEFINITION == "@":
  137. DEFINITION = "AT"
  138. elif DEFINITION == "#":
  139. DEFINITION = "HASH"
  140. elif DEFINITION == "$":
  141. DEFINITION = "DOLLAR"
  142. elif DEFINITION == "!":
  143. DEFINITION = "EXCLAIM"
  144. elif DEFINITION == "%":
  145. DEFINITION = "PERCENT"
  146. elif DEFINITION == "^":
  147. DEFINITION = "CIRCUMFLEX"
  148. elif DEFINITION == "&":
  149. DEFINITION = "AMPERSAND"
  150. elif DEFINITION == "|":
  151. DEFINITION = "PIPE"
  152. if DEFINITION in [
  153. "A", "a", "B", "b", "C", "c", "D", "d", "E", "e",
  154. "F", "f", "G", "g", "H", "h", "I", "i", "J", "j",
  155. "K", "k", "L", "l", "M", "m", "N", "n", "O", "o",
  156. "P", "p", "Q", "q", "R", "r", "S", "s", "T", "t",
  157. "U", "u", "V", "v", "W", "w", "X", "x", "Y", "y",
  158. "Z", "z", "1", "2", "3", "4", "5", "6", "7", "8",
  159. "9", "0", "F1", "F2", "F3", "F4", "F5", "F6", "F7",
  160. "F8", "F9", "F10", "F11", "F12", "F13", "F14", "F15",
  161. "F16", "F17", "F18", "F19", "F20", "F21", "F22",
  162. "F23", "F24", "ENTER", "ENT", "ESCAPE", "ESC",
  163. "BSPACE", "BSPC", "TAB", "SPACE", "SPC", "NONUS_HASH",
  164. "NUHS", "NONUS_BSLASH", "NUBS", "COMMA", "COMM",
  165. "DOT", "SLASH", "SLSH", "TILDE", "TILD", "EXCLAIM",
  166. "EXLM", "AT", "HASH", "DOLLAR", "DLR", "PERCENT",
  167. "PERC", "CIRCUMFLEX", "CIRC", "AMPERSAND", "AMPR",
  168. "ASTERISK", "ASTR", "LEFT_PAREN", "LPRN", "RIGHT_PAREN",
  169. "RPRN", "UNDERSCORE", "UNDS", "PLUS", "LEFT_CURLY_BRACE",
  170. "LCBR", "RIGHT_CURLY_BRACE", "RCBR", "PIPE", "COLON",
  171. "COLN", "DOUBLE_QUOTE", "DQUO", "DQT",
  172. "LEFT_ANGLE_BRACKET", "LABK", "LT", "RIGHT_ANGLE_BRACKET",
  173. "RABK", "GT", "QUESTION", "QUES", "SCOLON", "SCLN",
  174. "QUOTE", "QUOT", "LBRACKET", "LBRC", "RBRACKET", "RBRC",
  175. "BSLASH", "BSLS", "MINUS", "MINS", "EQUAL", "EQL",
  176. "GRAVE", "GRV", "ZKHK", "CAPSLOCK", "CLCK", "CAPS",
  177. "SCROLLOCK", "SLCK", "BRMD", "NUMLOCK", "NLCK",
  178. "LOCKING_CAPS", "LCAP", "LOCKING_NUM", "LNUM",
  179. "LOCKING_SCROLL", "LSCR", "LCTRL", "LCTL", "LSHIFT",
  180. "LSFT", "LALT", "LGUI", "LCMD", "LWIN", "RCTRL",
  181. "RCTL", "RSHIFT", "RSFT", "RALT", "RGUI", "RCMD",
  182. "RWIN", "INT1", "RO", "INT2", "KANA", "INT3", "JYEN",
  183. "INT4", "HENK", "INT5", "MHEN", "INT6", "INT7",
  184. "INT8", "INT9", "LANG1", "HAEN", "LANG2", "HANJ",
  185. "LANG3", "LANG4", "LANG5", "LANG6", "LANG7", "LANG8",
  186. "LANG9", "PSCREEN", "PSCR", "PAUSE", "PAUS", "BRK",
  187. "BRMU", "INSERT", "INS", "HOME", "PGUP", "DELETE",
  188. "DEL", "END", "PGDOWN", "PGDN", "RIGHT", "RGHT",
  189. "LEFT", "DOWN", "UP", "APPLICATION", "APP", "POWER",
  190. "EXECUTE", "EXEC", "HELP", "MENU", "SELECT", "SLCT",
  191. "STOP", "AGAIN", "AGIN", "UNDO", "CUT", "COPY",
  192. "PASTE", "PSTE", "FIND", "MUTE", "VOLUP", "VOLDOWN",
  193. "ALT_ERASE", "ERAS", "SYSREQ", "CANCEL", "CLEAR",
  194. "CLR", "PRIOR", "RETURN", "SEPARATOR", "OUT", "OPER",
  195. "CLEAR_AGAIN", "CRSEL", "EXSEL", "SYSTEM_POWER",
  196. "PWR", "SYSTEM_SLEEP", "SLEP", "SYSTEM_WAKE", "WAKE",
  197. "AUDIO_MUTE", "MUTE", "AUDIO_VOL_UP", "VOLU",
  198. "AUDIO_VOL_DOWN", "VOLD", "MEDIA_NEXT_TRACK", "MNXT",
  199. "MEDIA_PREV_TRACK", "MPRV", "CPRV", "MEDIA_STOP", "MSTP",
  200. "MEDIA_PLAY_PAUSE", "MPLY", "MEDIA_SELECT", "MSEL",
  201. "MEDIA_EJECT", "EJCT", "MAIL", "CALCULATOR", "CALC",
  202. "MY_COMPUTER", "MYCM", "WWW_SEARCH", "WSCH", "WWW_HOME",
  203. "WHOM", "WWW_BACK", "WBAK", "WWW_FORWARD", "WFWD",
  204. "WWW_STOP", "WSTP", "WWW_REFRESH", "WREF",
  205. "WWW_FAVORITES", "WFAV", "MEDIA_FAST_FORWARD", "MFFD",
  206. "MEDIA_REWIND", "MRWD", "BRIGHTNESS_UP", "BRIU",
  207. "BRIGHTNESS_DOWN", "BRID", "KP_SLASH", "PSLS",
  208. "KP_ASTERISK", "PAST", "KP_MINUS", "PMNS", "KP_PLUS",
  209. "PPLS", "KP_ENTER", "PENT", "KP_1", "P1", "KP_2", "P2",
  210. "KP_3", "P3", "KP_4", "P4", "KP_5", "P5", "KP_6", "P6",
  211. "KP_7", "P7", "KP_8", "P8", "KP_9", "P9", "KP_0", "P0",
  212. "KP_DOT", "PDOT", "KP_EQUAL", "PEQL", "KP_COMMA", "PCMM",
  213. "MS_BTN1", "BTN1", "MS_BTN2", "BTN2", "MS_BTN3", "BTN3",
  214. "MS_BTN4", "BTN4", "MS_BTN5", "BTN5", "MS_BTN6", "BTN6",
  215. "MS_LEFT", "MS_L", "MS_DOWN", "MS_D", "MS_UP", "MS_U",
  216. "MS_RIGHT", "MS_R", "MS_WH_UP", "WH_U", "MS_WH_DOWN",
  217. "WH_D", "MS_WH_LEFT", "MS_WH_L", "MS_WH_RIGHT", "MS_WH_R",
  218. "KC_MS_ACCEL0", "ACL0", "KC_MS_ACCEL1", "ACL1",
  219. "KC_MS_ACCEL2", "ACL2"
  220. ]:
  221. return "KC_" + DEFINITION
  222. else:
  223. return DEFINITION
  224. def MK(on_pseudolayer, keycodes_hash, definition, output_buffer, index):
  225. l = len(definition.split(', '))
  226. output_buffer += "void function_" + str(index) + "(const struct Chord* self) {\n"
  227. output_buffer += " switch (*self->state) {\n"
  228. output_buffer += " case ACTIVATED:\n"
  229. for i in range(0, l):
  230. val = definition.split(',')[i].strip()
  231. code = expand_keycode_fnc(val)
  232. output_buffer += " key_in(" + code + ");\n"
  233. output_buffer += " break;\n"
  234. output_buffer += " case DEACTIVATED:\n"
  235. for i in range(0, l):
  236. val = definition.split(',')[i].strip()
  237. code = expand_keycode_fnc(val)
  238. output_buffer += " key_out(" + code + ");\n"
  239. output_buffer += " *self->state = IDLE;\n"
  240. output_buffer += " break;\n"
  241. output_buffer += " case RESTART:\n"
  242. for i in range(0, l):
  243. val = definition.split(',')[i].strip()
  244. code = expand_keycode_fnc(val)
  245. output_buffer += " key_out(" + code + ");\n"
  246. output_buffer += " break;\n"
  247. output_buffer += " default:\n"
  248. output_buffer += " break;\n"
  249. output_buffer += " };\n"
  250. output_buffer += "}\n"
  251. return new_chord(on_pseudolayer, keycodes_hash, True, 0, 0, "function_" + str(index), output_buffer, index)
  252. def D(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index):
  253. l = len(DEFINITION.split(','))
  254. output_buffer += "void function_" + str(index) + "(const struct Chord* self) {\n"
  255. output_buffer += " switch (*self->state) {\n"
  256. output_buffer += " case ACTIVATED:\n"
  257. output_buffer += " *self->counter = *self->counter + 1;\n"
  258. output_buffer += " break;\n"
  259. output_buffer += " case PRESS_FROM_ACTIVE:\n"
  260. output_buffer += " switch (*self->counter) {\n"
  261. for i in range(0, l):
  262. val = DEFINITION.split(',')[i].strip()
  263. code = expand_keycode_fnc(val)
  264. output_buffer += " case " + str(i + 1) + ":\n"
  265. output_buffer += " key_in( " + code + ");\n"
  266. output_buffer += " break;\n"
  267. output_buffer += " default:\n"
  268. output_buffer += " break;\n"
  269. output_buffer += " }\n"
  270. output_buffer += " *self->state = FINISHED_FROM_ACTIVE;\n"
  271. output_buffer += " break;\n"
  272. output_buffer += " case FINISHED:\n"
  273. output_buffer += " switch (*self->counter) {\n"
  274. for i in range(0, l):
  275. val = DEFINITION.split(',')[i].strip()
  276. code = expand_keycode_fnc(val)
  277. output_buffer += " case " + str(i + 1) + ":\n"
  278. output_buffer += " tap_key( " + code + ");\n"
  279. output_buffer += " break;\n"
  280. output_buffer += " default:\n"
  281. output_buffer += " break;\n"
  282. output_buffer += " }\n"
  283. output_buffer += " *self->counter = 0;\n"
  284. output_buffer += " *self->state = IDLE;\n"
  285. output_buffer += " break;\n"
  286. output_buffer += " case RESTART:\n"
  287. output_buffer += " switch (*self->counter) {\n"
  288. for i in range(0, l):
  289. val = DEFINITION.split(',')[i].strip()
  290. code = expand_keycode_fnc(val)
  291. output_buffer += " case " + str(i + 1) + ":\n"
  292. output_buffer += " key_out( " + code + ");\n"
  293. output_buffer += " break;\n"
  294. output_buffer += " default:\n"
  295. output_buffer += " break;\n"
  296. output_buffer += " }\n"
  297. output_buffer += " *self->counter = 0;\n"
  298. output_buffer += " break;\n"
  299. output_buffer += " default:\n"
  300. output_buffer += " break;\n"
  301. output_buffer += " }\n"
  302. output_buffer += "}\n"
  303. return new_chord(on_pseudolayer, keycodes_hash, True, 0, 0, "function_" + str(index), output_buffer, index)
  304. def O(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index):
  305. if DEFINITION[0:3] == "KC_":
  306. return OSK(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index)
  307. else:
  308. return OSL(on_pseudolayer, keycodes_hash, DEFINITION, output_buffer, index)
  309. def add_key(PSEUDOLAYER, KEYCODES_HASH, DEFINITION, output_buffer, index, number_of_strings, strings):
  310. # if "= {" + KEYCODES_HASH + ", " + PSEUDOLAYER in output_buffer:
  311. # KEYCODES_HASH = re.sub('H_', '', KEYCODES_HASH)
  312. # raise Exception("You are trying to register a chord that you already registered (" + KEYCODES_HASH + ", " + PSEUDOLAYER + ")")
  313. if DEFINITION == "":
  314. return [output_buffer, index, number_of_strings, strings]
  315. else:
  316. split = DEFINITION.split("(")
  317. type = split[0].strip()
  318. if len(split) == 1:
  319. if type == "LOCK":
  320. [output_buffer, index] = LOCK(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  321. elif type == "AT":
  322. [output_buffer, index] = AT(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  323. elif type == "CMD":
  324. [output_buffer, index] = CMD(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  325. elif type == "LEAD":
  326. [output_buffer, index] = LEAD(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  327. elif type == "DM_RECORD":
  328. [output_buffer, index] = DM_RECORD(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  329. elif type == "DM_NEXT":
  330. [output_buffer, index] = DM_NEXT(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  331. elif type == "DM_END":
  332. [output_buffer, index] = DM_END(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  333. elif type == "DM_PLAY":
  334. [output_buffer, index] = DM_PLAY(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  335. elif type == "CLEAR_KB":
  336. [output_buffer, index] = CLEAR(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  337. elif type == "RESET":
  338. [output_buffer, index] = RESET(PSEUDOLAYER, KEYCODES_HASH, output_buffer, index)
  339. else:
  340. code = expand_keycode_fnc(type)
  341. [output_buffer, index] = KC(PSEUDOLAYER, KEYCODES_HASH, code, output_buffer, index)
  342. else:
  343. val = split[1][:-1].strip()
  344. if type == "O":
  345. code = expand_keycode_fnc(val)
  346. [output_buffer, index] = O(PSEUDOLAYER, KEYCODES_HASH, code, output_buffer, index)
  347. elif type == "D":
  348. [output_buffer, index] = D(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index)
  349. elif type == "MK":
  350. [output_buffer, index] = MK(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index)
  351. elif type == "M":
  352. fnc = val.split(',')[0].strip()
  353. val1 = val.split(',')[1].strip()
  354. val2 = val.split(',')[2].strip()
  355. [output_buffer, index] = M(PSEUDOLAYER, KEYCODES_HASH, val1, val2, fnc, output_buffer, index)
  356. elif type == "KK":
  357. val1 = val.split(',')[0].strip()
  358. code1 = expand_keycode_fnc(val1)
  359. val2 = val.split(',')[1].strip()
  360. code2 = expand_keycode_fnc(val2)
  361. [output_buffer, index] = KK(PSEUDOLAYER, KEYCODES_HASH, code1, code2, output_buffer, index)
  362. elif type == "KL":
  363. val1 = val.split(',')[0].strip()
  364. code1 = expand_keycode_fnc(val1)
  365. val2 = val.split(',')[1].strip()
  366. [output_buffer, index] = KL(PSEUDOLAYER, KEYCODES_HASH, code1, val2, output_buffer, index)
  367. elif type == "KM":
  368. val1 = val.split(',')[0].strip()
  369. code1 = expand_keycode_fnc(val1)
  370. val2 = val.split(',')[1].strip()
  371. code2 = expand_keycode_fnc(val2)
  372. [output_buffer, index] = KM(PSEUDOLAYER, KEYCODES_HASH, code1, code2, output_buffer, index)
  373. elif type == "AS":
  374. code = expand_keycode_fnc(val)
  375. [output_buffer, index] = AS(PSEUDOLAYER, KEYCODES_HASH, code, output_buffer, index)
  376. elif type == "MO":
  377. if not ',' in val:
  378. [output_buffer, index] = MO(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index)
  379. else:
  380. val1 = val.split(',')[0].strip()
  381. val2 = val.split(',')[1].strip()
  382. [output_buffer, index] = MO_alt(PSEUDOLAYER, KEYCODES_HASH, val1, val2, output_buffer, index)
  383. elif type == "DF":
  384. [output_buffer, index] = DF(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index)
  385. elif type == "TO":
  386. [output_buffer, index] = TO(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index)
  387. elif type == "STR":
  388. [output_buffer, index, number_of_strings, strings] = STR(PSEUDOLAYER, KEYCODES_HASH, val, output_buffer, index, number_of_strings, strings)
  389. return [output_buffer, index, number_of_strings, strings]
  390. def add_leader_combo(DEFINITION, FUNCTION):
  391. return list_of_leader_combos.append([DEFINITION, FUNCTION])
  392. def add_chord_set(PSEUDOLAYER, INPUT_STRING, TYPE, data, output_buffer, index, number_of_strings, strings):
  393. chord_set = {}
  394. for set in data["chord_sets"]:
  395. if set["name"] == TYPE:
  396. chord_set = set["chords"]
  397. break
  398. separated_string = top_level_split(INPUT_STRING)
  399. for word, chord in zip(separated_string, chord_set):
  400. chord_hash = reduce((lambda x, y: str(x) + " + " + str(y)), ["H_" + key for key in chord])
  401. [output_buffer, index, number_of_strings, strings] = add_key(PSEUDOLAYER, chord_hash, word, output_buffer, index, number_of_strings, strings)
  402. return [output_buffer, index, number_of_strings, strings]
  403. def add_dictionary(PSEUDOLAYER, keycodes, array, output_buffer, index, number_of_strings, strings):
  404. for chord in array:
  405. hash = ""
  406. for word, key in zip(chord[:-1], keycodes):
  407. if word == "X":
  408. hash = hash + " + H_" + key
  409. hash = hash[3:]
  410. if hash != "":
  411. [output_buffer, index, number_of_strings, strings] = add_key(PSEUDOLAYER, hash, chord[-1], output_buffer, index, number_of_strings, strings)
  412. return [output_buffer, index, number_of_strings, strings]
  413. def secret_chord(PSEUDOLAYER, ACTION, INPUT_STRING, data, output_buffer, index, number_of_strings, strings):
  414. separated_string = top_level_split(INPUT_STRING)
  415. hash = ""
  416. for word, key in zip(separated_string, data["keys"]):
  417. if word == "X":
  418. hash = hash + " + H_" + key
  419. hash = hash[3:]
  420. if hash != "":
  421. return add_key(PSEUDOLAYER, hash, ACTION, output_buffer, index, number_of_strings, strings)