action.c 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  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. || ((action.kind.id == ACT_LMODS_TAP || action.kind.id == ACT_RMODS_TAP) && (action.layer_tap.code <= MODS_TAP_TOGGLE || tap_count == 0))
  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
  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. # if defined(RETRO_TAPPING) && defined(DUMMY_MOD_NEUTRALIZER_KEYCODE)
  487. // Send a dummy keycode to neutralize flashing modifiers
  488. // if the key was held and then released with no interruptions.
  489. if (retro_tapping_counter == 2) {
  490. neutralize_flashing_modifiers(get_mods());
  491. }
  492. # endif
  493. unregister_mods(mods);
  494. }
  495. }
  496. break;
  497. }
  498. #endif // NO_ACTION_TAPPING
  499. } break;
  500. #ifdef EXTRAKEY_ENABLE
  501. /* other HID usage */
  502. case ACT_USAGE:
  503. switch (action.usage.page) {
  504. case PAGE_SYSTEM:
  505. host_system_send(event.pressed ? action.usage.code : 0);
  506. break;
  507. case PAGE_CONSUMER:
  508. host_consumer_send(event.pressed ? action.usage.code : 0);
  509. break;
  510. }
  511. break;
  512. #endif // EXTRAKEY_ENABLE
  513. /* Mouse key */
  514. case ACT_MOUSEKEY:
  515. register_mouse(action.key.code, event.pressed);
  516. break;
  517. #ifndef NO_ACTION_LAYER
  518. case ACT_LAYER:
  519. if (action.layer_bitop.on == 0) {
  520. /* Default Layer Bitwise Operation */
  521. if (!event.pressed) {
  522. uint8_t shift = action.layer_bitop.part * 4;
  523. layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift;
  524. layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0;
  525. switch (action.layer_bitop.op) {
  526. case OP_BIT_AND:
  527. default_layer_and(bits | mask);
  528. break;
  529. case OP_BIT_OR:
  530. default_layer_or(bits | mask);
  531. break;
  532. case OP_BIT_XOR:
  533. default_layer_xor(bits | mask);
  534. break;
  535. case OP_BIT_SET:
  536. default_layer_set(bits | mask);
  537. break;
  538. }
  539. }
  540. } else {
  541. /* Layer Bitwise Operation */
  542. if (event.pressed ? (action.layer_bitop.on & ON_PRESS) : (action.layer_bitop.on & ON_RELEASE)) {
  543. uint8_t shift = action.layer_bitop.part * 4;
  544. layer_state_t bits = ((layer_state_t)action.layer_bitop.bits) << shift;
  545. layer_state_t mask = (action.layer_bitop.xbit) ? ~(((layer_state_t)0xf) << shift) : 0;
  546. switch (action.layer_bitop.op) {
  547. case OP_BIT_AND:
  548. layer_and(bits | mask);
  549. break;
  550. case OP_BIT_OR:
  551. layer_or(bits | mask);
  552. break;
  553. case OP_BIT_XOR:
  554. layer_xor(bits | mask);
  555. break;
  556. case OP_BIT_SET:
  557. layer_state_set(bits | mask);
  558. break;
  559. }
  560. }
  561. }
  562. break;
  563. case ACT_LAYER_MODS:
  564. if (event.pressed) {
  565. layer_on(action.layer_mods.layer);
  566. register_mods(action.layer_mods.mods);
  567. } else {
  568. unregister_mods(action.layer_mods.mods);
  569. layer_off(action.layer_mods.layer);
  570. }
  571. break;
  572. case ACT_LAYER_TAP:
  573. case ACT_LAYER_TAP_EXT:
  574. switch (action.layer_tap.code) {
  575. # ifndef NO_ACTION_TAPPING
  576. case OP_TAP_TOGGLE:
  577. /* tap toggle */
  578. if (event.pressed) {
  579. if (tap_count < TAPPING_TOGGLE) {
  580. layer_invert(action.layer_tap.val);
  581. }
  582. } else {
  583. if (tap_count <= TAPPING_TOGGLE) {
  584. layer_invert(action.layer_tap.val);
  585. }
  586. }
  587. break;
  588. # endif
  589. case OP_ON_OFF:
  590. event.pressed ? layer_on(action.layer_tap.val) : layer_off(action.layer_tap.val);
  591. break;
  592. case OP_OFF_ON:
  593. event.pressed ? layer_off(action.layer_tap.val) : layer_on(action.layer_tap.val);
  594. break;
  595. case OP_SET_CLEAR:
  596. event.pressed ? layer_move(action.layer_tap.val) : layer_clear();
  597. break;
  598. # if !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
  599. case OP_ONESHOT:
  600. // Oneshot modifier
  601. if (!keymap_config.oneshot_enable) {
  602. if (event.pressed) {
  603. layer_on(action.layer_tap.val);
  604. } else {
  605. layer_off(action.layer_tap.val);
  606. }
  607. } else {
  608. # if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  609. do_release_oneshot = false;
  610. if (event.pressed) {
  611. if (get_oneshot_layer_state() == ONESHOT_TOGGLED) {
  612. reset_oneshot_layer();
  613. layer_off(action.layer_tap.val);
  614. break;
  615. } else if (tap_count < ONESHOT_TAP_TOGGLE) {
  616. layer_on(action.layer_tap.val);
  617. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  618. }
  619. } else {
  620. if (tap_count >= ONESHOT_TAP_TOGGLE) {
  621. reset_oneshot_layer();
  622. set_oneshot_layer(action.layer_tap.val, ONESHOT_TOGGLED);
  623. } else {
  624. clear_oneshot_layer_state(ONESHOT_PRESSED);
  625. }
  626. }
  627. # else
  628. if (event.pressed) {
  629. layer_on(action.layer_tap.val);
  630. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  631. } else {
  632. clear_oneshot_layer_state(ONESHOT_PRESSED);
  633. if (tap_count > 1) {
  634. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  635. }
  636. }
  637. # endif
  638. }
  639. # else // NO_ACTION_ONESHOT && NO_ACTION_TAPPING
  640. if (event.pressed) {
  641. layer_on(action.layer_tap.val);
  642. } else {
  643. layer_off(action.layer_tap.val);
  644. }
  645. # endif // !defined(NO_ACTION_ONESHOT) && !defined(NO_ACTION_TAPPING)
  646. break;
  647. default:
  648. # ifndef NO_ACTION_TAPPING /* tap key */
  649. if (event.pressed) {
  650. if (tap_count > 0) {
  651. ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n");
  652. register_code(action.layer_tap.code);
  653. } else {
  654. ac_dprintf("KEYMAP_TAP_KEY: No tap: On on press\n");
  655. layer_on(action.layer_tap.val);
  656. }
  657. } else {
  658. if (tap_count > 0) {
  659. ac_dprintf("KEYMAP_TAP_KEY: Tap: unregister_code\n");
  660. if (action.layer_tap.code == KC_CAPS_LOCK) {
  661. wait_ms(TAP_HOLD_CAPS_DELAY);
  662. } else {
  663. wait_ms(TAP_CODE_DELAY);
  664. }
  665. unregister_code(action.layer_tap.code);
  666. } else {
  667. ac_dprintf("KEYMAP_TAP_KEY: No tap: Off on release\n");
  668. layer_off(action.layer_tap.val);
  669. }
  670. }
  671. # else
  672. if (event.pressed) {
  673. ac_dprintf("KEYMAP_TAP_KEY: Tap: register_code\n");
  674. register_code(action.layer_tap.code);
  675. } else {
  676. ac_dprintf("KEYMAP_TAP_KEY: Tap: unregister_code\n");
  677. if (action.layer_tap.code == KC_CAPS) {
  678. wait_ms(TAP_HOLD_CAPS_DELAY);
  679. } else {
  680. wait_ms(TAP_CODE_DELAY);
  681. }
  682. unregister_code(action.layer_tap.code);
  683. }
  684. # endif
  685. break;
  686. }
  687. break;
  688. #endif // NO_ACTION_LAYER
  689. #ifdef SWAP_HANDS_ENABLE
  690. case ACT_SWAP_HANDS:
  691. switch (action.swap.code) {
  692. case OP_SH_TOGGLE:
  693. if (event.pressed) {
  694. swap_hands = !swap_hands;
  695. }
  696. break;
  697. case OP_SH_ON_OFF:
  698. swap_hands = event.pressed;
  699. break;
  700. case OP_SH_OFF_ON:
  701. swap_hands = !event.pressed;
  702. break;
  703. case OP_SH_ON:
  704. if (!event.pressed) {
  705. swap_hands = true;
  706. }
  707. break;
  708. case OP_SH_OFF:
  709. if (!event.pressed) {
  710. swap_hands = false;
  711. }
  712. break;
  713. # ifndef NO_ACTION_ONESHOT
  714. case OP_SH_ONESHOT:
  715. if (event.pressed) {
  716. set_oneshot_swaphands();
  717. } else {
  718. release_oneshot_swaphands();
  719. }
  720. break;
  721. # endif
  722. # ifndef NO_ACTION_TAPPING
  723. case OP_SH_TAP_TOGGLE:
  724. /* tap toggle */
  725. if (event.pressed) {
  726. if (swap_held) {
  727. swap_held = false;
  728. } else {
  729. swap_hands = !swap_hands;
  730. }
  731. } else {
  732. if (tap_count < TAPPING_TOGGLE) {
  733. swap_hands = !swap_hands;
  734. }
  735. }
  736. break;
  737. default:
  738. /* tap key */
  739. if (tap_count > 0) {
  740. if (swap_held) {
  741. swap_hands = !swap_hands; // undo hold set up in _tap_hint
  742. swap_held = false;
  743. }
  744. if (event.pressed) {
  745. register_code(action.swap.code);
  746. } else {
  747. wait_ms(TAP_CODE_DELAY);
  748. unregister_code(action.swap.code);
  749. *record = (keyrecord_t){}; // hack: reset tap mode
  750. }
  751. } else {
  752. if (swap_held && !event.pressed) {
  753. swap_hands = !swap_hands; // undo hold set up in _tap_hint
  754. swap_held = false;
  755. }
  756. }
  757. # endif
  758. }
  759. #endif
  760. default:
  761. break;
  762. }
  763. #ifndef NO_ACTION_LAYER
  764. // if this event is a layer action, update the leds
  765. switch (action.kind.id) {
  766. case ACT_LAYER:
  767. case ACT_LAYER_MODS:
  768. # ifndef NO_ACTION_TAPPING
  769. case ACT_LAYER_TAP:
  770. case ACT_LAYER_TAP_EXT:
  771. # endif
  772. led_set(host_keyboard_leds());
  773. break;
  774. default:
  775. break;
  776. }
  777. #endif
  778. #ifndef NO_ACTION_TAPPING
  779. # if defined(RETRO_TAPPING) || defined(RETRO_TAPPING_PER_KEY) || (defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT))
  780. if (!is_tap_action(action)) {
  781. retro_tapping_counter = 0;
  782. } else {
  783. if (event.pressed) {
  784. if (tap_count > 0) {
  785. retro_tapping_counter = 0;
  786. }
  787. } else {
  788. if (tap_count > 0) {
  789. retro_tapping_counter = 0;
  790. } else {
  791. if (
  792. # ifdef RETRO_TAPPING_PER_KEY
  793. get_retro_tapping(get_event_keycode(record->event, false), record) &&
  794. # endif
  795. retro_tapping_counter == 2) {
  796. # if defined(AUTO_SHIFT_ENABLE) && defined(RETRO_SHIFT)
  797. process_auto_shift(action.layer_tap.code, record);
  798. # else
  799. tap_code(action.layer_tap.code);
  800. # endif
  801. }
  802. retro_tapping_counter = 0;
  803. }
  804. }
  805. }
  806. # endif
  807. #endif
  808. #ifdef SWAP_HANDS_ENABLE
  809. # ifndef NO_ACTION_ONESHOT
  810. if (event.pressed && !(action.kind.id == ACT_SWAP_HANDS && action.swap.code == OP_SH_ONESHOT)) {
  811. use_oneshot_swaphands();
  812. }
  813. # endif
  814. #endif
  815. #ifndef NO_ACTION_ONESHOT
  816. /* Because we switch layers after a oneshot event, we need to release the
  817. * key before we leave the layer or no key up event will be generated.
  818. */
  819. if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED)) {
  820. record->event.pressed = false;
  821. layer_on(get_oneshot_layer());
  822. process_record(record);
  823. layer_off(get_oneshot_layer());
  824. }
  825. #endif
  826. }
  827. /** \brief Utilities for actions. (FIXME: Needs better description)
  828. *
  829. * FIXME: Needs documentation.
  830. */
  831. __attribute__((weak)) void register_code(uint8_t code) {
  832. if (code == KC_NO) {
  833. return;
  834. #ifdef LOCKING_SUPPORT_ENABLE
  835. } else if (KC_LOCKING_CAPS_LOCK == code) {
  836. # ifdef LOCKING_RESYNC_ENABLE
  837. // Resync: ignore if caps lock already is on
  838. if (host_keyboard_led_state().caps_lock) return;
  839. # endif
  840. add_key(KC_CAPS_LOCK);
  841. send_keyboard_report();
  842. wait_ms(TAP_HOLD_CAPS_DELAY);
  843. del_key(KC_CAPS_LOCK);
  844. send_keyboard_report();
  845. } else if (KC_LOCKING_NUM_LOCK == code) {
  846. # ifdef LOCKING_RESYNC_ENABLE
  847. if (host_keyboard_led_state().num_lock) return;
  848. # endif
  849. add_key(KC_NUM_LOCK);
  850. send_keyboard_report();
  851. wait_ms(100);
  852. del_key(KC_NUM_LOCK);
  853. send_keyboard_report();
  854. } else if (KC_LOCKING_SCROLL_LOCK == code) {
  855. # ifdef LOCKING_RESYNC_ENABLE
  856. if (host_keyboard_led_state().scroll_lock) return;
  857. # endif
  858. add_key(KC_SCROLL_LOCK);
  859. send_keyboard_report();
  860. wait_ms(100);
  861. del_key(KC_SCROLL_LOCK);
  862. send_keyboard_report();
  863. #endif
  864. } else if (IS_BASIC_KEYCODE(code)) {
  865. // TODO: should push command_proc out of this block?
  866. if (command_proc(code)) return;
  867. // Force a new key press if the key is already pressed
  868. // without this, keys with the same keycode, but different
  869. // modifiers will be reported incorrectly, see issue #1708
  870. if (is_key_pressed(code)) {
  871. del_key(code);
  872. send_keyboard_report();
  873. }
  874. add_key(code);
  875. send_keyboard_report();
  876. } else if (IS_MODIFIER_KEYCODE(code)) {
  877. add_mods(MOD_BIT(code));
  878. send_keyboard_report();
  879. #ifdef EXTRAKEY_ENABLE
  880. } else if (IS_SYSTEM_KEYCODE(code)) {
  881. host_system_send(KEYCODE2SYSTEM(code));
  882. } else if (IS_CONSUMER_KEYCODE(code)) {
  883. host_consumer_send(KEYCODE2CONSUMER(code));
  884. #endif
  885. } else if (IS_MOUSE_KEYCODE(code)) {
  886. register_mouse(code, true);
  887. }
  888. }
  889. /** \brief Utilities for actions. (FIXME: Needs better description)
  890. *
  891. * FIXME: Needs documentation.
  892. */
  893. __attribute__((weak)) void unregister_code(uint8_t code) {
  894. if (code == KC_NO) {
  895. return;
  896. #ifdef LOCKING_SUPPORT_ENABLE
  897. } else if (KC_LOCKING_CAPS_LOCK == code) {
  898. # ifdef LOCKING_RESYNC_ENABLE
  899. // Resync: ignore if caps lock already is off
  900. if (!host_keyboard_led_state().caps_lock) return;
  901. # endif
  902. add_key(KC_CAPS_LOCK);
  903. send_keyboard_report();
  904. del_key(KC_CAPS_LOCK);
  905. send_keyboard_report();
  906. } else if (KC_LOCKING_NUM_LOCK == code) {
  907. # ifdef LOCKING_RESYNC_ENABLE
  908. if (!host_keyboard_led_state().num_lock) return;
  909. # endif
  910. add_key(KC_NUM_LOCK);
  911. send_keyboard_report();
  912. del_key(KC_NUM_LOCK);
  913. send_keyboard_report();
  914. } else if (KC_LOCKING_SCROLL_LOCK == code) {
  915. # ifdef LOCKING_RESYNC_ENABLE
  916. if (!host_keyboard_led_state().scroll_lock) return;
  917. # endif
  918. add_key(KC_SCROLL_LOCK);
  919. send_keyboard_report();
  920. del_key(KC_SCROLL_LOCK);
  921. send_keyboard_report();
  922. #endif
  923. } else if (IS_BASIC_KEYCODE(code)) {
  924. del_key(code);
  925. send_keyboard_report();
  926. } else if (IS_MODIFIER_KEYCODE(code)) {
  927. del_mods(MOD_BIT(code));
  928. send_keyboard_report();
  929. #ifdef EXTRAKEY_ENABLE
  930. } else if (IS_SYSTEM_KEYCODE(code)) {
  931. host_system_send(0);
  932. } else if (IS_CONSUMER_KEYCODE(code)) {
  933. host_consumer_send(0);
  934. #endif
  935. } else if (IS_MOUSE_KEYCODE(code)) {
  936. register_mouse(code, false);
  937. }
  938. }
  939. /** \brief Tap a keycode with a delay.
  940. *
  941. * \param code The basic keycode to tap.
  942. * \param delay The amount of time in milliseconds to leave the keycode registered, before unregistering it.
  943. */
  944. __attribute__((weak)) void tap_code_delay(uint8_t code, uint16_t delay) {
  945. register_code(code);
  946. for (uint16_t i = delay; i > 0; i--) {
  947. wait_ms(1);
  948. }
  949. unregister_code(code);
  950. }
  951. /** \brief Tap a keycode with the default delay.
  952. *
  953. * \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.
  954. */
  955. __attribute__((weak)) void tap_code(uint8_t code) {
  956. tap_code_delay(code, code == KC_CAPS_LOCK ? TAP_HOLD_CAPS_DELAY : TAP_CODE_DELAY);
  957. }
  958. /** \brief Adds the given physically pressed modifiers and sends a keyboard report immediately.
  959. *
  960. * \param mods A bitfield of modifiers to register.
  961. */
  962. __attribute__((weak)) void register_mods(uint8_t mods) {
  963. if (mods) {
  964. add_mods(mods);
  965. send_keyboard_report();
  966. }
  967. }
  968. /** \brief Removes the given physically pressed modifiers and sends a keyboard report immediately.
  969. *
  970. * \param mods A bitfield of modifiers to unregister.
  971. */
  972. __attribute__((weak)) void unregister_mods(uint8_t mods) {
  973. if (mods) {
  974. del_mods(mods);
  975. send_keyboard_report();
  976. }
  977. }
  978. /** \brief Adds the given weak modifiers and sends a keyboard report immediately.
  979. *
  980. * \param mods A bitfield of modifiers to register.
  981. */
  982. __attribute__((weak)) void register_weak_mods(uint8_t mods) {
  983. if (mods) {
  984. add_weak_mods(mods);
  985. send_keyboard_report();
  986. }
  987. }
  988. /** \brief Removes the given weak modifiers and sends a keyboard report immediately.
  989. *
  990. * \param mods A bitfield of modifiers to unregister.
  991. */
  992. __attribute__((weak)) void unregister_weak_mods(uint8_t mods) {
  993. if (mods) {
  994. del_weak_mods(mods);
  995. send_keyboard_report();
  996. }
  997. }
  998. /** \brief Utilities for actions. (FIXME: Needs better description)
  999. *
  1000. * FIXME: Needs documentation.
  1001. */
  1002. void clear_keyboard(void) {
  1003. clear_mods();
  1004. clear_keyboard_but_mods();
  1005. }
  1006. /** \brief Utilities for actions. (FIXME: Needs better description)
  1007. *
  1008. * FIXME: Needs documentation.
  1009. */
  1010. void clear_keyboard_but_mods(void) {
  1011. clear_keys();
  1012. clear_keyboard_but_mods_and_keys();
  1013. }
  1014. /** \brief Utilities for actions. (FIXME: Needs better description)
  1015. *
  1016. * FIXME: Needs documentation.
  1017. */
  1018. void clear_keyboard_but_mods_and_keys(void) {
  1019. #ifdef EXTRAKEY_ENABLE
  1020. host_system_send(0);
  1021. host_consumer_send(0);
  1022. #endif
  1023. clear_weak_mods();
  1024. send_keyboard_report();
  1025. #ifdef MOUSEKEY_ENABLE
  1026. mousekey_clear();
  1027. mousekey_send();
  1028. #endif
  1029. #ifdef PROGRAMMABLE_BUTTON_ENABLE
  1030. programmable_button_clear();
  1031. #endif
  1032. }
  1033. /** \brief Utilities for actions. (FIXME: Needs better description)
  1034. *
  1035. * FIXME: Needs documentation.
  1036. */
  1037. bool is_tap_record(keyrecord_t *record) {
  1038. if (IS_NOEVENT(record->event)) {
  1039. return false;
  1040. }
  1041. #if defined(COMBO_ENABLE) || defined(REPEAT_KEY_ENABLE)
  1042. action_t action;
  1043. if (record->keycode) {
  1044. action = action_for_keycode(record->keycode);
  1045. } else {
  1046. action = layer_switch_get_action(record->event.key);
  1047. }
  1048. #else
  1049. action_t action = layer_switch_get_action(record->event.key);
  1050. #endif
  1051. return is_tap_action(action);
  1052. }
  1053. /** \brief Utilities for actions. (FIXME: Needs better description)
  1054. *
  1055. * FIXME: Needs documentation.
  1056. */
  1057. bool is_tap_action(action_t action) {
  1058. switch (action.kind.id) {
  1059. case ACT_LMODS_TAP:
  1060. case ACT_RMODS_TAP:
  1061. case ACT_LAYER_TAP:
  1062. case ACT_LAYER_TAP_EXT:
  1063. switch (action.layer_tap.code) {
  1064. case KC_NO ... KC_RIGHT_GUI:
  1065. case OP_TAP_TOGGLE:
  1066. case OP_ONESHOT:
  1067. return true;
  1068. }
  1069. return false;
  1070. case ACT_SWAP_HANDS:
  1071. switch (action.swap.code) {
  1072. case KC_NO ... KC_RIGHT_GUI:
  1073. case OP_SH_TAP_TOGGLE:
  1074. return true;
  1075. }
  1076. return false;
  1077. }
  1078. return false;
  1079. }
  1080. /** \brief Debug print (FIXME: Needs better description)
  1081. *
  1082. * FIXME: Needs documentation.
  1083. */
  1084. void debug_event(keyevent_t event) {
  1085. ac_dprintf("%04X%c(%u)", (event.key.row << 8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time);
  1086. }
  1087. /** \brief Debug print (FIXME: Needs better description)
  1088. *
  1089. * FIXME: Needs documentation.
  1090. */
  1091. void debug_record(keyrecord_t record) {
  1092. debug_event(record.event);
  1093. #ifndef NO_ACTION_TAPPING
  1094. ac_dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' '));
  1095. #endif
  1096. }
  1097. /** \brief Debug print (FIXME: Needs better description)
  1098. *
  1099. * FIXME: Needs documentation.
  1100. */
  1101. void debug_action(action_t action) {
  1102. switch (action.kind.id) {
  1103. case ACT_LMODS:
  1104. ac_dprintf("ACT_LMODS");
  1105. break;
  1106. case ACT_RMODS:
  1107. ac_dprintf("ACT_RMODS");
  1108. break;
  1109. case ACT_LMODS_TAP:
  1110. ac_dprintf("ACT_LMODS_TAP");
  1111. break;
  1112. case ACT_RMODS_TAP:
  1113. ac_dprintf("ACT_RMODS_TAP");
  1114. break;
  1115. case ACT_USAGE:
  1116. ac_dprintf("ACT_USAGE");
  1117. break;
  1118. case ACT_MOUSEKEY:
  1119. ac_dprintf("ACT_MOUSEKEY");
  1120. break;
  1121. case ACT_LAYER:
  1122. ac_dprintf("ACT_LAYER");
  1123. break;
  1124. case ACT_LAYER_MODS:
  1125. ac_dprintf("ACT_LAYER_MODS");
  1126. break;
  1127. case ACT_LAYER_TAP:
  1128. ac_dprintf("ACT_LAYER_TAP");
  1129. break;
  1130. case ACT_LAYER_TAP_EXT:
  1131. ac_dprintf("ACT_LAYER_TAP_EXT");
  1132. break;
  1133. case ACT_SWAP_HANDS:
  1134. ac_dprintf("ACT_SWAP_HANDS");
  1135. break;
  1136. default:
  1137. ac_dprintf("UNKNOWN");
  1138. break;
  1139. }
  1140. ac_dprintf("[%X:%02X]", action.kind.param >> 8, action.kind.param & 0xff);
  1141. }