action.c 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215
  1. /*
  2. Copyright 2012,2013 Jun Wako <wakojun@gmail.com>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. */
  14. #include <limits.h>
  15. #include "host.h"
  16. #include "keycode.h"
  17. #include "keyboard.h"
  18. #include "mousekey.h"
  19. #include "programmable_button.h"
  20. #include "command.h"
  21. #include "led.h"
  22. #include "action_layer.h"
  23. #include "action_tapping.h"
  24. #include "action_util.h"
  25. #include "action.h"
  26. #include "wait.h"
  27. #include "keycode_config.h"
  28. #include "debug.h"
  29. #include "quantum.h"
  30. #ifdef BACKLIGHT_ENABLE
  31. # include "backlight.h"
  32. #endif
  33. #ifdef POINTING_DEVICE_ENABLE
  34. # include "pointing_device.h"
  35. #endif
  36. #if defined(ENCODER_ENABLE) && defined(ENCODER_MAP_ENABLE) && defined(SWAP_HANDS_ENABLE)
  37. # include "encoder.h"
  38. #endif
  39. int tp_buttons;
  40. #if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
  41. int retro_tapping_counter = 0;
  42. #endif
  43. #if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT) && !defined(NO_ACTION_TAPPING)
  44. # include "process_auto_shift.h"
  45. #endif
  46. #ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
  47. __attribute__((weak)) bool get_hold_on_other_key_press(uint16_t keycode, keyrecord_t *record) {
  48. return false;
  49. }
  50. #endif
  51. #ifdef RETRO_TAPPING_PER_KEY
  52. __attribute__((weak)) bool get_retro_tapping(uint16_t keycode, keyrecord_t *record) {
  53. return false;
  54. }
  55. #endif
  56. /** \brief Called to execute an action.
  57. *
  58. * FIXME: Needs documentation.
  59. */
  60. void action_exec(keyevent_t event) {
  61. if (IS_EVENT(event)) {
  62. ac_dprintf("\n---- action_exec: start -----\n");
  63. ac_dprintf("EVENT: ");
  64. debug_event(event);
  65. ac_dprintf("\n");
  66. #if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
  67. retro_tapping_counter++;
  68. #endif
  69. }
  70. if (event.pressed) {
  71. // clear the potential weak mods left by previously pressed keys
  72. clear_weak_mods();
  73. }
  74. #ifdef SWAP_HANDS_ENABLE
  75. // Swap hands handles both keys and encoders, if ENCODER_MAP_ENABLE is defined.
  76. if (IS_EVENT(event)) {
  77. process_hand_swap(&event);
  78. }
  79. #endif
  80. keyrecord_t record = {.event = event};
  81. #ifndef NO_ACTION_ONESHOT
  82. if (keymap_config.oneshot_enable) {
  83. # if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
  84. if (has_oneshot_layer_timed_out()) {
  85. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  86. }
  87. if (has_oneshot_mods_timed_out()) {
  88. clear_oneshot_mods();
  89. }
  90. # ifdef SWAP_HANDS_ENABLE
  91. if (has_oneshot_swaphands_timed_out()) {
  92. clear_oneshot_swaphands();
  93. }
  94. # endif
  95. # endif
  96. }
  97. #endif
  98. #ifndef NO_ACTION_TAPPING
  99. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  100. if (event.pressed) {
  101. retroshift_poll_time(&event);
  102. }
  103. # endif
  104. if (IS_NOEVENT(record.event) || pre_process_record_quantum(&record)) {
  105. action_tapping_process(record);
  106. }
  107. #else
  108. if (IS_NOEVENT(record.event) || pre_process_record_quantum(&record)) {
  109. process_record(&record);
  110. }
  111. if (IS_EVENT(record.event)) {
  112. ac_dprintf("processed: ");
  113. debug_record(record);
  114. dprintln();
  115. }
  116. #endif
  117. }
  118. #ifdef SWAP_HANDS_ENABLE
  119. extern const keypos_t PROGMEM hand_swap_config[MATRIX_ROWS][MATRIX_COLS];
  120. # ifdef ENCODER_MAP_ENABLE
  121. extern const uint8_t PROGMEM encoder_hand_swap_config[NUM_ENCODERS];
  122. # endif // ENCODER_MAP_ENABLE
  123. bool swap_hands = false;
  124. bool swap_held = false;
  125. bool should_swap_hands(size_t index, uint8_t *swap_state, bool pressed) {
  126. size_t array_index = index / (CHAR_BIT);
  127. size_t bit_index = index % (CHAR_BIT);
  128. uint8_t bit_val = 1 << bit_index;
  129. bool do_swap = pressed ? swap_hands : swap_state[array_index] & bit_val;
  130. return do_swap;
  131. }
  132. void set_swap_hands_state(size_t index, uint8_t *swap_state, bool on) {
  133. size_t array_index = index / (CHAR_BIT);
  134. size_t bit_index = index % (CHAR_BIT);
  135. uint8_t bit_val = 1 << bit_index;
  136. if (on) {
  137. swap_state[array_index] |= bit_val;
  138. } else {
  139. swap_state[array_index] &= ~bit_val;
  140. }
  141. }
  142. void swap_hands_on(void) {
  143. swap_hands = true;
  144. }
  145. void swap_hands_off(void) {
  146. swap_hands = false;
  147. }
  148. void swap_hands_toggle(void) {
  149. swap_hands = !swap_hands;
  150. }
  151. bool is_swap_hands_on(void) {
  152. return swap_hands;
  153. }
  154. /** \brief Process Hand Swap
  155. *
  156. * FIXME: Needs documentation.
  157. */
  158. void process_hand_swap(keyevent_t *event) {
  159. keypos_t pos = event->key;
  160. if (IS_KEYEVENT(*event) && pos.row < MATRIX_ROWS && pos.col < MATRIX_COLS) {
  161. static uint8_t matrix_swap_state[((MATRIX_ROWS * MATRIX_COLS) + (CHAR_BIT)-1) / (CHAR_BIT)];
  162. size_t index = (size_t)(pos.row * MATRIX_COLS) + pos.col;
  163. bool do_swap = should_swap_hands(index, matrix_swap_state, event->pressed);
  164. if (do_swap) {
  165. event->key.row = pgm_read_byte(&hand_swap_config[pos.row][pos.col].row);
  166. event->key.col = pgm_read_byte(&hand_swap_config[pos.row][pos.col].col);
  167. set_swap_hands_state(index, matrix_swap_state, true);
  168. } else {
  169. set_swap_hands_state(index, matrix_swap_state, false);
  170. }
  171. }
  172. # ifdef ENCODER_MAP_ENABLE
  173. else if (IS_ENCODEREVENT(*event) && (pos.row == KEYLOC_ENCODER_CW || pos.row == KEYLOC_ENCODER_CCW)) {
  174. static uint8_t encoder_swap_state[((NUM_ENCODERS) + (CHAR_BIT)-1) / (CHAR_BIT)];
  175. size_t index = pos.col;
  176. bool do_swap = should_swap_hands(index, encoder_swap_state, event->pressed);
  177. if (do_swap) {
  178. event->key.row = pos.row;
  179. event->key.col = pgm_read_byte(&encoder_hand_swap_config[pos.col]);
  180. set_swap_hands_state(index, encoder_swap_state, true);
  181. } else {
  182. set_swap_hands_state(index, encoder_swap_state, false);
  183. }
  184. }
  185. # endif // ENCODER_MAP_ENABLE
  186. }
  187. #endif
  188. #if !defined(NO_ACTION_LAYER) && !defined(STRICT_LAYER_RELEASE)
  189. bool disable_action_cache = false;
  190. void process_record_nocache(keyrecord_t *record) {
  191. disable_action_cache = true;
  192. process_record(record);
  193. disable_action_cache = false;
  194. }
  195. #else
  196. void process_record_nocache(keyrecord_t *record) {
  197. process_record(record);
  198. }
  199. #endif
  200. __attribute__((weak)) bool process_record_quantum(keyrecord_t *record) {
  201. return true;
  202. }
  203. __attribute__((weak)) void post_process_record_quantum(keyrecord_t *record) {}
  204. #ifndef NO_ACTION_TAPPING
  205. /** \brief Allows for handling tap-hold actions immediately instead of waiting for TAPPING_TERM or another keypress.
  206. *
  207. * FIXME: Needs documentation.
  208. */
  209. void process_record_tap_hint(keyrecord_t *record) {
  210. if (!IS_KEYEVENT(record->event)) {
  211. return;
  212. }
  213. action_t action = layer_switch_get_action(record->event.key);
  214. switch (action.kind.id) {
  215. # ifdef SWAP_HANDS_ENABLE
  216. case ACT_SWAP_HANDS:
  217. switch (action.swap.code) {
  218. case OP_SH_ONESHOT:
  219. break;
  220. case OP_SH_TAP_TOGGLE:
  221. default:
  222. swap_hands = !swap_hands;
  223. swap_held = true;
  224. }
  225. break;
  226. # endif
  227. }
  228. }
  229. #endif
  230. /** \brief Take a key event (key press or key release) and processes it.
  231. *
  232. * FIXME: Needs documentation.
  233. */
  234. void process_record(keyrecord_t *record) {
  235. if (IS_NOEVENT(record->event)) {
  236. return;
  237. }
  238. if (!process_record_quantum(record)) {
  239. #ifndef NO_ACTION_ONESHOT
  240. if (is_oneshot_layer_active() && record->event.pressed && keymap_config.oneshot_enable) {
  241. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  242. }
  243. #endif
  244. return;
  245. }
  246. process_record_handler(record);
  247. post_process_record_quantum(record);
  248. }
  249. void process_record_handler(keyrecord_t *record) {
  250. #if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE)
  251. action_t action;
  252. if (record->keycode) {
  253. action = action_for_keycode(record->keycode);
  254. } else {
  255. action = store_or_get_action(record->event.pressed, record->event.key);
  256. }
  257. #else
  258. action_t action = store_or_get_action(record->event.pressed, record->event.key);
  259. #endif
  260. ac_dprintf("ACTION: ");
  261. debug_action(action);
  262. #ifndef NO_ACTION_LAYER
  263. ac_dprintf(" layer_state: ");
  264. layer_debug();
  265. ac_dprintf(" default_layer_state: ");
  266. default_layer_debug();
  267. #endif
  268. ac_dprintf("\n");
  269. process_action(record, action);
  270. }
  271. /**
  272. * @brief handles all the messy mouse stuff
  273. *
  274. * Handles all the edgecases and special stuff that is needed for coexistense
  275. * of the multiple mouse subsystems.
  276. *
  277. * @param mouse_keycode[in] uint8_t mouse keycode
  278. * @param pressed[in] bool
  279. */
  280. void register_mouse(uint8_t mouse_keycode, bool pressed) {
  281. #ifdef MOUSEKEY_ENABLE
  282. // if mousekeys is enabled, let it do the brunt of the work
  283. if (pressed) {
  284. mousekey_on(mouse_keycode);
  285. } else {
  286. mousekey_off(mouse_keycode);
  287. }
  288. // should mousekeys send report, or does something else handle this?
  289. switch (mouse_keycode) {
  290. # if defined(PS2_MOUSE_ENABLE) || defined(POINTING_DEVICE_ENABLE)
  291. case KC_MS_BTN1 ... KC_MS_BTN8:
  292. // let pointing device handle the buttons
  293. // expand if/when it handles more of the code
  294. # if defined(POINTING_DEVICE_ENABLE)
  295. pointing_device_keycode_handler(mouse_keycode, pressed);
  296. # endif
  297. break;
  298. # endif
  299. default:
  300. mousekey_send();
  301. break;
  302. }
  303. #elif defined(POINTING_DEVICE_ENABLE)
  304. // if mousekeys isn't enabled, and pointing device is enabled, then
  305. // let pointing device do all the heavy lifting, then
  306. if (IS_MOUSE_KEYCODE(mouse_keycode)) {
  307. pointing_device_keycode_handler(mouse_keycode, pressed);
  308. }
  309. #endif
  310. #ifdef PS2_MOUSE_ENABLE
  311. // make sure that ps2 mouse has button report synced
  312. if (KC_MS_BTN1 <= mouse_keycode && mouse_keycode <= KC_MS_BTN3) {
  313. uint8_t tmp_button_msk = MOUSE_BTN_MASK(mouse_keycode - KC_MS_BTN1);
  314. tp_buttons = pressed ? tp_buttons | tmp_button_msk : tp_buttons & ~tmp_button_msk;
  315. }
  316. #endif
  317. }
  318. /** \brief Take an action and processes it.
  319. *
  320. * FIXME: Needs documentation.
  321. */
  322. void process_action(keyrecord_t *record, action_t action) {
  323. keyevent_t event = record->event;
  324. #ifndef NO_ACTION_TAPPING
  325. uint8_t tap_count = record->tap.count;
  326. #endif
  327. #ifndef NO_ACTION_ONESHOT
  328. bool do_release_oneshot = false;
  329. // notice we only clear the one shot layer if the pressed key is not a modifier.
  330. if (is_oneshot_layer_active() && event.pressed &&
  331. (action.kind.id == ACT_USAGE || !(IS_MODIFIER_KEYCODE(action.key.code)
  332. # ifndef NO_ACTION_TAPPING
  333. || (tap_count == 0 && (action.kind.id == ACT_LMODS_TAP || action.kind.id == ACT_RMODS_TAP))
  334. # endif
  335. ))
  336. # ifdef SWAP_HANDS_ENABLE
  337. && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)
  338. # endif
  339. && keymap_config.oneshot_enable) {
  340. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  341. do_release_oneshot = !is_oneshot_layer_active();
  342. }
  343. #endif
  344. switch (action.kind.id) {
  345. /* Key and Mods */
  346. case ACT_LMODS:
  347. case ACT_RMODS: {
  348. uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods : action.key.mods << 4;
  349. if (event.pressed) {
  350. if (mods) {
  351. if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
  352. // e.g. LSFT(KC_LEFT_GUI): we don't want the LSFT to be weak as it would make it useless.
  353. // This also makes LSFT(KC_LEFT_GUI) behave exactly the same as LGUI(KC_LEFT_SHIFT).
  354. // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
  355. add_mods(mods);
  356. } else {
  357. add_weak_mods(mods);
  358. }
  359. send_keyboard_report();
  360. }
  361. register_code(action.key.code);
  362. } else {
  363. unregister_code(action.key.code);
  364. if (mods) {
  365. if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
  366. del_mods(mods);
  367. } else {
  368. del_weak_mods(mods);
  369. }
  370. send_keyboard_report();
  371. }
  372. }
  373. } break;
  374. case ACT_LMODS_TAP:
  375. case ACT_RMODS_TAP: {
  376. #ifndef NO_ACTION_TAPPING
  377. uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods : action.key.mods << 4;
  378. switch (action.layer_tap.code) {
  379. # ifndef NO_ACTION_ONESHOT
  380. case MODS_ONESHOT:
  381. // Oneshot modifier
  382. if (!keymap_config.oneshot_enable) {
  383. if (event.pressed) {
  384. if (mods) {
  385. if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
  386. // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
  387. // This also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT).
  388. // Same applies for some keys like KC_MEH which are declared as MEH(KC_NO).
  389. add_mods(mods);
  390. } else {
  391. add_weak_mods(mods);
  392. }
  393. send_keyboard_report();
  394. }
  395. register_code(action.key.code);
  396. } else {
  397. unregister_code(action.key.code);
  398. if (mods) {
  399. if (IS_MODIFIER_KEYCODE(action.key.code) || action.key.code == KC_NO) {
  400. del_mods(mods);
  401. } else {
  402. del_weak_mods(mods);
  403. }
  404. send_keyboard_report();
  405. }
  406. }
  407. } else {
  408. if (event.pressed) {
  409. if (tap_count == 0) {
  410. // Not a tap, but a hold: register the held mod
  411. ac_dprintf("MODS_TAP: Oneshot: 0\n");
  412. register_mods(mods);
  413. } else if (tap_count == 1) {
  414. ac_dprintf("MODS_TAP: Oneshot: start\n");
  415. add_oneshot_mods(mods);
  416. # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  417. } else if (tap_count == ONESHOT_TAP_TOGGLE) {
  418. ac_dprintf("MODS_TAP: Toggling oneshot");
  419. register_mods(mods);
  420. del_oneshot_mods(mods);
  421. add_oneshot_locked_mods(mods);
  422. # endif
  423. }
  424. } else {
  425. if (tap_count == 0) {
  426. // Release hold: unregister the held mod and its variants
  427. unregister_mods(mods);
  428. del_oneshot_mods(mods);
  429. del_oneshot_locked_mods(mods);
  430. # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  431. } else if (tap_count == 1 && (mods & get_mods())) {
  432. unregister_mods(mods);
  433. del_oneshot_mods(mods);
  434. del_oneshot_locked_mods(mods);
  435. # endif
  436. }
  437. }
  438. }
  439. break;
  440. # endif
  441. case MODS_TAP_TOGGLE:
  442. if (event.pressed) {
  443. if (tap_count <= TAPPING_TOGGLE) {
  444. register_mods(mods);
  445. }
  446. } else {
  447. if (tap_count < TAPPING_TOGGLE) {
  448. unregister_mods(mods);
  449. }
  450. }
  451. break;
  452. default:
  453. if (event.pressed) {
  454. if (tap_count > 0) {
  455. # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
  456. if (
  457. # ifdef HOLD_ON_OTHER_KEY_PRESS_PER_KEY
  458. get_hold_on_other_key_press(get_event_keycode(record->event, false), record) &&
  459. # endif
  460. record->tap.interrupted) {
  461. ac_dprintf("mods_tap: tap: cancel: add_mods\n");
  462. // ad hoc: set 0 to cancel tap
  463. record->tap.count = 0;
  464. register_mods(mods);
  465. } else
  466. # endif
  467. {
  468. ac_dprintf("MODS_TAP: Tap: register_code\n");
  469. register_code(action.key.code);
  470. }
  471. } else {
  472. ac_dprintf("MODS_TAP: No tap: add_mods\n");
  473. register_mods(mods);
  474. }
  475. } else {
  476. if (tap_count > 0) {
  477. ac_dprintf("MODS_TAP: Tap: unregister_code\n");
  478. if (action.layer_tap.code == KC_CAPS_LOCK) {
  479. wait_ms(TAP_HOLD_CAPS_DELAY);
  480. } else {
  481. wait_ms(TAP_CODE_DELAY);
  482. }
  483. unregister_code(action.key.code);
  484. } else {
  485. ac_dprintf("MODS_TAP: No tap: add_mods\n");
  486. unregister_mods(mods);
  487. }
  488. }
  489. break;
  490. }
  491. #endif // NO_ACTION_TAPPING
  492. } break;
  493. #ifdef EXTRAKEY_ENABLE
  494. /* other HID usage */
  495. case ACT_USAGE:
  496. switch (action.usage.page) {
  497. case PAGE_SYSTEM:
  498. host_system_send(event.pressed ? action.usage.code : 0);
  499. break;
  500. case PAGE_CONSUMER:
  501. host_consumer_send(event.pressed ? action.usage.code : 0);
  502. break;
  503. }
  504. break;
  505. #endif // EXTRAKEY_ENABLE
  506. /* Mouse key */
  507. case ACT_MOUSEKEY:
  508. register_mouse(action.key.code, event.pressed);
  509. break;
  510. #ifndef NO_ACTION_LAYER
  511. case ACT_LAYER:
  512. if (action.layer_bitop.on == 0) {
  513. /* Default Layer Bitwise Operation */
  514. if (!event.pressed) {
  515. uint8_t shift = action.layer_bitop.part * 4;
  516. layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift;
  517. layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0;
  518. switch (action.layer_bitop.op) {
  519. case OP_BIT_AND:
  520. default_layer_and(bits | mask);
  521. break;
  522. case OP_BIT_OR:
  523. default_layer_or(bits | mask);
  524. break;
  525. case OP_BIT_XOR:
  526. default_layer_xor(bits | mask);
  527. break;
  528. case OP_BIT_SET:
  529. default_layer_set(bits | mask);
  530. break;
  531. }
  532. }
  533. } else {
  534. /* Layer Bitwise Operation */
  535. if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : (action.layer_bitop.on & ON_RELEASE)) {
  536. uint8_t shift = action.layer_bitop.part * 4;
  537. layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift;
  538. layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0;
  539. switch (action.layer_bitop.op) {
  540. case OP_BIT_AND:
  541. layer_and(bits | mask);
  542. break;
  543. case OP_BIT_OR:
  544. layer_or(bits | mask);
  545. break;
  546. case OP_BIT_XOR:
  547. layer_xor(bits | mask);
  548. break;
  549. case OP_BIT_SET:
  550. layer_state_set(bits | mask);
  551. break;
  552. }
  553. }
  554. }
  555. break;
  556. case ACT_LAYER_MODS:
  557. if (event.pressed) {
  558. layer_on(action.layer_mods.layer);
  559. register_mods(action.layer_mods.mods);
  560. } else {
  561. unregister_mods(action.layer_mods.mods);
  562. layer_off(action.layer_mods.layer);
  563. }
  564. break;
  565. case ACT_LAYER_TAP:
  566. case ACT_LAYER_TAP_EXT:
  567. switch (action.layer_tap.code) {
  568. # ifndef NO_ACTION_TAPPING
  569. case OP_TAP_TOGGLE:
  570. /* tap toggle */
  571. if (event.pressed) {
  572. if (tap_count < TAPPING_TOGGLE) {
  573. layer_invert(action.layer_tap.val);
  574. }
  575. } else {
  576. if (tap_count <= TAPPING_TOGGLE) {
  577. layer_invert(action.layer_tap.val);
  578. }
  579. }
  580. break;
  581. # endif
  582. case OP_ON_OFF:
  583. event.pressed ? layer_on(action.layer_tap.val) : layer_off(action.layer_tap.val);
  584. break;
  585. case OP_OFF_ON:
  586. event.pressed ? layer_off(action.layer_tap.val) : layer_on(action.layer_tap.val);
  587. break;
  588. case OP_SET_CLEAR:
  589. event.pressed ? layer_move(action.layer_tap.val) : layer_clear();
  590. break;
  591. # if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
  592. case OP_ONESHOT:
  593. // Oneshot modifier
  594. if (!keymap_config.oneshot_enable) {
  595. if (event.pressed) {
  596. layer_on(action.layer_tap.val);
  597. } else {
  598. layer_off(action.layer_tap.val);
  599. }
  600. } else {
  601. # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  602. do_release_oneshot = false;
  603. if (event.pressed) {
  604. if (get_oneshot_layer_state() == ONESHOT_TOGGLED) {
  605. reset_oneshot_layer();
  606. layer_off(action.layer_tap.val);
  607. break;
  608. } else if (tap_count < ONESHOT_TAP_TOGGLE) {
  609. layer_on(action.layer_tap.val);
  610. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  611. }
  612. } else {
  613. if (tap_count >= ONESHOT_TAP_TOGGLE) {
  614. reset_oneshot_layer();
  615. set_oneshot_layer(action.layer_tap.val, ONESHOT_TOGGLED);
  616. } else {
  617. clear_oneshot_layer_state(ONESHOT_PRESSED);
  618. }
  619. }
  620. # else
  621. if (event.pressed) {
  622. layer_on(action.layer_tap.val);
  623. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  624. } else {
  625. clear_oneshot_layer_state(ONESHOT_PRESSED);
  626. if (tap_count > 1) {
  627. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  628. }
  629. }
  630. # endif
  631. }
  632. # else // NO_ACTION_ONESHOT && NO_ACTION_TAPPING
  633. if (event.pressed) {
  634. layer_on(action.layer_tap.val);
  635. } else {
  636. layer_off(action.layer_tap.val);
  637. }
  638. # endif // !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
  639. break;
  640. default:
  641. # ifndef NO_ACTION_TAPPING /* tap key */
  642. if (event.pressed) {
  643. if (tap_count > 0) {
  644. ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n");
  645. register_code(action.layer_tap.code);
  646. } else {
  647. ac_dprintf("KEYMAP_TAP_KEY: No tap: On on press\n");
  648. layer_on(action.layer_tap.val);
  649. }
  650. } else {
  651. if (tap_count > 0) {
  652. ac_dprintf("KEYMAP_TAP_KEY: Tap: unregister_code\n");
  653. if (action.layer_tap.code == KC_CAPS_LOCK) {
  654. wait_ms(TAP_HOLD_CAPS_DELAY);
  655. } else {
  656. wait_ms(TAP_CODE_DELAY);
  657. }
  658. unregister_code(action.layer_tap.code);
  659. } else {
  660. ac_dprintf("KEYMAP_TAP_KEY: No tap: Off on release\n");
  661. layer_off(action.layer_tap.val);
  662. }
  663. }
  664. # else
  665. if (event.pressed) {
  666. ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n");
  667. register_code(action.layer_tap.code);
  668. } else {
  669. ac_dprintf("KEYMAP_TAP_KEY: Tap: unregister_code\n");
  670. if (action.layer_tap.code == KC_CAPS) {
  671. wait_ms(TAP_HOLD_CAPS_DELAY);
  672. } else {
  673. wait_ms(TAP_CODE_DELAY);
  674. }
  675. unregister_code(action.layer_tap.code);
  676. }
  677. # endif
  678. break;
  679. }
  680. break;
  681. #endif // NO_ACTION_LAYER
  682. #ifdef SWAP_HANDS_ENABLE
  683. case ACT_SWAP_HANDS:
  684. switch (action.swap.code) {
  685. case OP_SH_TOGGLE:
  686. if (event.pressed) {
  687. swap_hands = !swap_hands;
  688. }
  689. break;
  690. case OP_SH_ON_OFF:
  691. swap_hands = event.pressed;
  692. break;
  693. case OP_SH_OFF_ON:
  694. swap_hands = !event.pressed;
  695. break;
  696. case OP_SH_ON:
  697. if (!event.pressed) {
  698. swap_hands = true;
  699. }
  700. break;
  701. case OP_SH_OFF:
  702. if (!event.pressed) {
  703. swap_hands = false;
  704. }
  705. break;
  706. # ifndef NO_ACTION_ONESHOT
  707. case OP_SH_ONESHOT:
  708. if (event.pressed) {
  709. set_oneshot_swaphands();
  710. } else {
  711. release_oneshot_swaphands();
  712. }
  713. break;
  714. # endif
  715. # ifndef NO_ACTION_TAPPING
  716. case OP_SH_TAP_TOGGLE:
  717. /* tap toggle */
  718. if (event.pressed) {
  719. if (swap_held) {
  720. swap_held = false;
  721. } else {
  722. swap_hands = !swap_hands;
  723. }
  724. } else {
  725. if (tap_count < TAPPING_TOGGLE) {
  726. swap_hands = !swap_hands;
  727. }
  728. }
  729. break;
  730. default:
  731. /* tap key */
  732. if (tap_count > 0) {
  733. if (swap_held) {
  734. swap_hands = !swap_hands; // undo hold set up in _tap_hint
  735. swap_held = false;
  736. }
  737. if (event.pressed) {
  738. register_code(action.swap.code);
  739. } else {
  740. wait_ms(TAP_CODE_DELAY);
  741. unregister_code(action.swap.code);
  742. *record = (keyrecord_t){}; // hack: reset tap mode
  743. }
  744. } else {
  745. if (swap_held && !event.pressed) {
  746. swap_hands = !swap_hands; // undo hold set up in _tap_hint
  747. swap_held = false;
  748. }
  749. }
  750. # endif
  751. }
  752. #endif
  753. default:
  754. break;
  755. }
  756. #ifndef NO_ACTION_LAYER
  757. // if this event is a layer action, update the leds
  758. switch (action.kind.id) {
  759. case ACT_LAYER:
  760. case ACT_LAYER_MODS:
  761. # ifndef NO_ACTION_TAPPING
  762. case ACT_LAYER_TAP:
  763. case ACT_LAYER_TAP_EXT:
  764. # endif
  765. led_set(host_keyboard_leds());
  766. break;
  767. default:
  768. break;
  769. }
  770. #endif
  771. #ifndef NO_ACTION_TAPPING
  772. # if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
  773. if (!is_tap_action(action)) {
  774. retro_tapping_counter = 0;
  775. } else {
  776. if (event.pressed) {
  777. if (tap_count > 0) {
  778. retro_tapping_counter = 0;
  779. }
  780. } else {
  781. if (tap_count > 0) {
  782. retro_tapping_counter = 0;
  783. } else {
  784. if (
  785. # ifdef RETRO_TAPPING_PER_KEY
  786. get_retro_tapping(get_event_keycode(record->event, false), record) &&
  787. # endif
  788. retro_tapping_counter == 2) {
  789. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  790. process_auto_shift(action.layer_tap.code, record);
  791. # else
  792. tap_code(action.layer_tap.code);
  793. # endif
  794. }
  795. retro_tapping_counter = 0;
  796. }
  797. }
  798. }
  799. # endif
  800. #endif
  801. #ifdef SWAP_HANDS_ENABLE
  802. # ifndef NO_ACTION_ONESHOT
  803. if (event.pressed && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)) {
  804. use_oneshot_swaphands();
  805. }
  806. # endif
  807. #endif
  808. #ifndef NO_ACTION_ONESHOT
  809. /* Because we switch layers after a oneshot event, we need to release the
  810. * key before we leave the layer or no key up event will be generated.
  811. */
  812. if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED)) {
  813. record->event.pressed = false;
  814. layer_on(get_oneshot_layer());
  815. process_record(record);
  816. layer_off(get_oneshot_layer());
  817. }
  818. #endif
  819. }
  820. /** \brief Utilities for actions. (FIXME: Needs better description)
  821. *
  822. * FIXME: Needs documentation.
  823. */
  824. __attribute__((weak)) void register_code(uint8_t code) {
  825. if (code == KC_NO) {
  826. return;
  827. #ifdef LOCKING_SUPPORT_ENABLE
  828. } else if (KC_LOCKING_CAPS_LOCK == code) {
  829. # ifdef LOCKING_RESYNC_ENABLE
  830. // Resync: ignore if caps lock already is on
  831. if (host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK)) return;
  832. # endif
  833. add_key(KC_CAPS_LOCK);
  834. send_keyboard_report();
  835. wait_ms(TAP_HOLD_CAPS_DELAY);
  836. del_key(KC_CAPS_LOCK);
  837. send_keyboard_report();
  838. } else if (KC_LOCKING_NUM_LOCK == code) {
  839. # ifdef LOCKING_RESYNC_ENABLE
  840. if (host_keyboard_leds() & (1 << USB_LED_NUM_LOCK)) return;
  841. # endif
  842. add_key(KC_NUM_LOCK);
  843. send_keyboard_report();
  844. wait_ms(100);
  845. del_key(KC_NUM_LOCK);
  846. send_keyboard_report();
  847. } else if (KC_LOCKING_SCROLL_LOCK == code) {
  848. # ifdef LOCKING_RESYNC_ENABLE
  849. if (host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK)) return;
  850. # endif
  851. add_key(KC_SCROLL_LOCK);
  852. send_keyboard_report();
  853. wait_ms(100);
  854. del_key(KC_SCROLL_LOCK);
  855. send_keyboard_report();
  856. #endif
  857. } else if (IS_BASIC_KEYCODE(code)) {
  858. // TODO: should push command_proc out of this block?
  859. if (command_proc(code)) return;
  860. // Force a new key press if the key is already pressed
  861. // without this, keys with the same keycode, but different
  862. // modifiers will be reported incorrectly, see issue #1708
  863. if (is_key_pressed(keyboard_report, code)) {
  864. del_key(code);
  865. send_keyboard_report();
  866. }
  867. add_key(code);
  868. send_keyboard_report();
  869. } else if (IS_MODIFIER_KEYCODE(code)) {
  870. add_mods(MOD_BIT(code));
  871. send_keyboard_report();
  872. #ifdef EXTRAKEY_ENABLE
  873. } else if (IS_SYSTEM_KEYCODE(code)) {
  874. host_system_send(KEYCODE2SYSTEM(code));
  875. } else if (IS_CONSUMER_KEYCODE(code)) {
  876. host_consumer_send(KEYCODE2CONSUMER(code));
  877. #endif
  878. } else if (IS_MOUSE_KEYCODE(code)) {
  879. register_mouse(code, true);
  880. }
  881. }
  882. /** \brief Utilities for actions. (FIXME: Needs better description)
  883. *
  884. * FIXME: Needs documentation.
  885. */
  886. __attribute__((weak)) void unregister_code(uint8_t code) {
  887. if (code == KC_NO) {
  888. return;
  889. #ifdef LOCKING_SUPPORT_ENABLE
  890. } else if (KC_LOCKING_CAPS_LOCK == code) {
  891. # ifdef LOCKING_RESYNC_ENABLE
  892. // Resync: ignore if caps lock already is off
  893. if (!(host_keyboard_leds() & (1 << USB_LED_CAPS_LOCK))) return;
  894. # endif
  895. add_key(KC_CAPS_LOCK);
  896. send_keyboard_report();
  897. del_key(KC_CAPS_LOCK);
  898. send_keyboard_report();
  899. } else if (KC_LOCKING_NUM_LOCK == code) {
  900. # ifdef LOCKING_RESYNC_ENABLE
  901. if (!(host_keyboard_leds() & (1 << USB_LED_NUM_LOCK))) return;
  902. # endif
  903. add_key(KC_NUM_LOCK);
  904. send_keyboard_report();
  905. del_key(KC_NUM_LOCK);
  906. send_keyboard_report();
  907. } else if (KC_LOCKING_SCROLL_LOCK == code) {
  908. # ifdef LOCKING_RESYNC_ENABLE
  909. if (!(host_keyboard_leds() & (1 << USB_LED_SCROLL_LOCK))) return;
  910. # endif
  911. add_key(KC_SCROLL_LOCK);
  912. send_keyboard_report();
  913. del_key(KC_SCROLL_LOCK);
  914. send_keyboard_report();
  915. #endif
  916. } else if (IS_BASIC_KEYCODE(code)) {
  917. del_key(code);
  918. send_keyboard_report();
  919. } else if (IS_MODIFIER_KEYCODE(code)) {
  920. del_mods(MOD_BIT(code));
  921. send_keyboard_report();
  922. #ifdef EXTRAKEY_ENABLE
  923. } else if (IS_SYSTEM_KEYCODE(code)) {
  924. host_system_send(0);
  925. } else if (IS_CONSUMER_KEYCODE(code)) {
  926. host_consumer_send(0);
  927. #endif
  928. } else if (IS_MOUSE_KEYCODE(code)) {
  929. register_mouse(code, false);
  930. }
  931. }
  932. /** \brief Tap a keycode with a delay.
  933. *
  934. * \param code The basic keycode to tap.
  935. * \param delay The amount of time in milliseconds to leave the keycode registered, before unregistering it.
  936. */
  937. __attribute__((weak)) void tap_code_delay(uint8_t code, uint16_t delay) {
  938. register_code(code);
  939. for (uint16_t i = delay; i > 0; i--) {
  940. wait_ms(1);
  941. }
  942. unregister_code(code);
  943. }
  944. /** \brief Tap a keycode with the default delay.
  945. *
  946. * \param code The basic keycode to tap. If `code` is `KC_CAPS_LOCK`, the delay will be `TAP_HOLD_CAPS_DELAY`, otherwise `TAP_CODE_DELAY`, if defined.
  947. */
  948. __attribute__((weak)) void tap_code(uint8_t code) {
  949. tap_code_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY);
  950. }
  951. /** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately.
  952. *
  953. * \param mods A bitfield of modifiers to register.
  954. */
  955. __attribute__((weak)) void register_mods(uint8_t mods) {
  956. if (mods) {
  957. add_mods(mods);
  958. send_keyboard_report();
  959. }
  960. }
  961. /** \brief Removes the given physically pressed modifiers and sends a keyboard report immediately.
  962. *
  963. * \param mods A bitfield of modifiers to unregister.
  964. */
  965. __attribute__((weak)) void unregister_mods(uint8_t mods) {
  966. if (mods) {
  967. del_mods(mods);
  968. send_keyboard_report();
  969. }
  970. }
  971. /** \brief Adds the given weak modifiers and sends a keyboard report immediately.
  972. *
  973. * \param mods A bitfield of modifiers to register.
  974. */
  975. __attribute__((weak)) void register_weak_mods(uint8_t mods) {
  976. if (mods) {
  977. add_weak_mods(mods);
  978. send_keyboard_report();
  979. }
  980. }
  981. /** \brief Removes the given weak modifiers and sends a keyboard report immediately.
  982. *
  983. * \param mods A bitfield of modifiers to unregister.
  984. */
  985. __attribute__((weak)) void unregister_weak_mods(uint8_t mods) {
  986. if (mods) {
  987. del_weak_mods(mods);
  988. send_keyboard_report();
  989. }
  990. }
  991. /** \brief Utilities for actions. (FIXME: Needs better description)
  992. *
  993. * FIXME: Needs documentation.
  994. */
  995. void clear_keyboard(void) {
  996. clear_mods();
  997. clear_keyboard_but_mods();
  998. }
  999. /** \brief Utilities for actions. (FIXME: Needs better description)
  1000. *
  1001. * FIXME: Needs documentation.
  1002. */
  1003. void clear_keyboard_but_mods(void) {
  1004. clear_keys();
  1005. clear_keyboard_but_mods_and_keys();
  1006. }
  1007. /** \brief Utilities for actions. (FIXME: Needs better description)
  1008. *
  1009. * FIXME: Needs documentation.
  1010. */
  1011. void clear_keyboard_but_mods_and_keys(void) {
  1012. #ifdef EXTRAKEY_ENABLE
  1013. host_system_send(0);
  1014. host_consumer_send(0);
  1015. #endif
  1016. clear_weak_mods();
  1017. send_keyboard_report();
  1018. #ifdef MOUSEKEY_ENABLE
  1019. mousekey_clear();
  1020. mousekey_send();
  1021. #endif
  1022. #ifdef PROGRAMMABLE_BUTTON_ENABLE
  1023. programmable_button_clear();
  1024. #endif
  1025. }
  1026. /** \brief Utilities for actions. (FIXME: Needs better description)
  1027. *
  1028. * FIXME: Needs documentation.
  1029. */
  1030. bool is_tap_record(keyrecord_t *record) {
  1031. if (IS_NOEVENT(record->event)) {
  1032. return false;
  1033. }
  1034. #if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE)
  1035. action_t action;
  1036. if (record->keycode) {
  1037. action = action_for_keycode(record->keycode);
  1038. } else {
  1039. action = layer_switch_get_action(record->event.key);
  1040. }
  1041. #else
  1042. action_t action = layer_switch_get_action(record->event.key);
  1043. #endif
  1044. return is_tap_action(action);
  1045. }
  1046. /** \brief Utilities for actions. (FIXME: Needs better description)
  1047. *
  1048. * FIXME: Needs documentation.
  1049. */
  1050. bool is_tap_action(action_t action) {
  1051. switch (action.kind.id) {
  1052. case ACT_LMODS_TAP:
  1053. case ACT_RMODS_TAP:
  1054. case ACT_LAYER_TAP:
  1055. case ACT_LAYER_TAP_EXT:
  1056. switch (action.layer_tap.code) {
  1057. case KC_NO ... KC_RIGHT_GUI:
  1058. case OP_TAP_TOGGLE:
  1059. case OP_ONESHOT:
  1060. return true;
  1061. }
  1062. return false;
  1063. case ACT_SWAP_HANDS:
  1064. switch (action.swap.code) {
  1065. case KC_NO ... KC_RIGHT_GUI:
  1066. case OP_SH_TAP_TOGGLE:
  1067. return true;
  1068. }
  1069. return false;
  1070. }
  1071. return false;
  1072. }
  1073. /** \brief Debug print (FIXME: Needs better description)
  1074. *
  1075. * FIXME: Needs documentation.
  1076. */
  1077. void debug_event(keyevent_t event) {
  1078. ac_dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time);
  1079. }
  1080. /** \brief Debug print (FIXME: Needs better description)
  1081. *
  1082. * FIXME: Needs documentation.
  1083. */
  1084. void debug_record(keyrecord_t record) {
  1085. debug_event(record.event);
  1086. #ifndef NO_ACTION_TAPPING
  1087. ac_dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' '));
  1088. #endif
  1089. }
  1090. /** \brief Debug print (FIXME: Needs better description)
  1091. *
  1092. * FIXME: Needs documentation.
  1093. */
  1094. void debug_action(action_t action) {
  1095. switch (action.kind.id) {
  1096. case ACT_LMODS:
  1097. ac_dprintf("ACT_LMODS");
  1098. break;
  1099. case ACT_RMODS:
  1100. ac_dprintf("ACT_RMODS");
  1101. break;
  1102. case ACT_LMODS_TAP:
  1103. ac_dprintf("ACT_LMODS_TAP");
  1104. break;
  1105. case ACT_RMODS_TAP:
  1106. ac_dprintf("ACT_RMODS_TAP");
  1107. break;
  1108. case ACT_USAGE:
  1109. ac_dprintf("ACT_USAGE");
  1110. break;
  1111. case ACT_MOUSEKEY:
  1112. ac_dprintf("ACT_MOUSEKEY");
  1113. break;
  1114. case ACT_LAYER:
  1115. ac_dprintf("ACT_LAYER");
  1116. break;
  1117. case ACT_LAYER_MODS:
  1118. ac_dprintf("ACT_LAYER_MODS");
  1119. break;
  1120. case ACT_LAYER_TAP:
  1121. ac_dprintf("ACT_LAYER_TAP");
  1122. break;
  1123. case ACT_LAYER_TAP_EXT:
  1124. ac_dprintf("ACT_LAYER_TAP_EXT");
  1125. break;
  1126. case ACT_SWAP_HANDS:
  1127. ac_dprintf("ACT_SWAP_HANDS");
  1128. break;
  1129. default:
  1130. ac_dprintf("UNKNOWN");
  1131. break;
  1132. }
  1133. ac_dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff);
  1134. }