chord.py 22 KB

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