upload
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

action.c 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. /*
  2. Copyright 2012,2013 Jun Wako <[email protected]>
  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 "host.h"
  15. #include "keycode.h"
  16. #include "keyboard.h"
  17. #include "mousekey.h"
  18. #include "command.h"
  19. #include "led.h"
  20. #include "backlight.h"
  21. #include "action_layer.h"
  22. #include "action_tapping.h"
  23. #include "action_macro.h"
  24. #include "action_util.h"
  25. #include "action.h"
  26. #ifdef DEBUG_ACTION
  27. #include "debug.h"
  28. #else
  29. #include "nodebug.h"
  30. #endif
  31. void action_exec(keyevent_t event)
  32. {
  33. if (!IS_NOEVENT(event)) {
  34. dprint("\n---- action_exec: start -----\n");
  35. dprint("EVENT: "); debug_event(event); dprintln();
  36. }
  37. keyrecord_t record = { .event = event };
  38. #ifndef NO_ACTION_TAPPING
  39. action_tapping_process(record);
  40. #else
  41. process_record(&record);
  42. if (!IS_NOEVENT(record.event)) {
  43. dprint("processed: "); debug_record(record); dprintln();
  44. }
  45. #endif
  46. }
  47. #if !defined(NO_ACTION_LAYER) && defined(PREVENT_STUCK_MODIFIERS)
  48. bool disable_action_cache = false;
  49. void process_record_nocache(keyrecord_t *record)
  50. {
  51. disable_action_cache = true;
  52. process_record(record);
  53. disable_action_cache = false;
  54. }
  55. #else
  56. void process_record_nocache(keyrecord_t *record)
  57. {
  58. process_record(record);
  59. }
  60. #endif
  61. __attribute__ ((weak))
  62. bool process_record_quantum(keyrecord_t *record) {
  63. return true;
  64. }
  65. void process_record(keyrecord_t *record)
  66. {
  67. if (IS_NOEVENT(record->event)) { return; }
  68. if(!process_record_quantum(record))
  69. return;
  70. action_t action = store_or_get_action(record->event.pressed, record->event.key);
  71. dprint("ACTION: "); debug_action(action);
  72. #ifndef NO_ACTION_LAYER
  73. dprint(" layer_state: "); layer_debug();
  74. dprint(" default_layer_state: "); default_layer_debug();
  75. #endif
  76. dprintln();
  77. process_action(record, action);
  78. }
  79. void process_action(keyrecord_t *record, action_t action)
  80. {
  81. bool do_release_oneshot = false;
  82. keyevent_t event = record->event;
  83. #ifndef NO_ACTION_TAPPING
  84. uint8_t tap_count = record->tap.count;
  85. #endif
  86. #if (defined(ONESHOT_TIMEOUT) && (ONESHOT_TIMEOUT > 0))
  87. if (has_oneshot_layer_timed_out()) {
  88. dprintf("Oneshot layer: timeout\n");
  89. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  90. }
  91. #endif
  92. if (event.pressed) {
  93. // clear the potential weak mods left by previously pressed keys
  94. clear_weak_mods();
  95. }
  96. #ifndef NO_ACTION_ONESHOT
  97. // notice we only clear the one shot layer if the pressed key is not a modifier.
  98. if (is_oneshot_layer_active() && event.pressed && !IS_MOD(action.key.code)) {
  99. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  100. do_release_oneshot = !is_oneshot_layer_active();
  101. }
  102. #endif
  103. switch (action.kind.id) {
  104. /* Key and Mods */
  105. case ACT_LMODS:
  106. case ACT_RMODS:
  107. {
  108. uint8_t mods = (action.kind.id == ACT_LMODS) ? action.key.mods :
  109. action.key.mods<<4;
  110. if (event.pressed) {
  111. if (mods) {
  112. if (IS_MOD(action.key.code)) {
  113. // e.g. LSFT(KC_LGUI): we don't want the LSFT to be weak as it would make it useless.
  114. // this also makes LSFT(KC_LGUI) behave exactly the same as LGUI(KC_LSFT)
  115. add_mods(mods);
  116. } else {
  117. add_weak_mods(mods);
  118. }
  119. send_keyboard_report();
  120. }
  121. register_code(action.key.code);
  122. } else {
  123. unregister_code(action.key.code);
  124. if (mods) {
  125. if (IS_MOD(action.key.code)) {
  126. del_mods(mods);
  127. } else {
  128. del_weak_mods(mods);
  129. }
  130. send_keyboard_report();
  131. }
  132. }
  133. }
  134. break;
  135. #ifndef NO_ACTION_TAPPING
  136. case ACT_LMODS_TAP:
  137. case ACT_RMODS_TAP:
  138. {
  139. uint8_t mods = (action.kind.id == ACT_LMODS_TAP) ? action.key.mods :
  140. action.key.mods<<4;
  141. switch (action.layer_tap.code) {
  142. #ifndef NO_ACTION_ONESHOT
  143. case MODS_ONESHOT:
  144. // Oneshot modifier
  145. if (event.pressed) {
  146. if (tap_count == 0) {
  147. dprint("MODS_TAP: Oneshot: 0\n");
  148. register_mods(mods);
  149. } else if (tap_count == 1) {
  150. dprint("MODS_TAP: Oneshot: start\n");
  151. set_oneshot_mods(mods);
  152. #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  153. } else if (tap_count == ONESHOT_TAP_TOGGLE) {
  154. dprint("MODS_TAP: Toggling oneshot");
  155. clear_oneshot_mods();
  156. set_oneshot_locked_mods(mods);
  157. register_mods(mods);
  158. #endif
  159. } else {
  160. register_mods(mods);
  161. }
  162. } else {
  163. if (tap_count == 0) {
  164. clear_oneshot_mods();
  165. unregister_mods(mods);
  166. } else if (tap_count == 1) {
  167. // Retain Oneshot mods
  168. #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  169. if (mods & get_mods()) {
  170. clear_oneshot_locked_mods();
  171. clear_oneshot_mods();
  172. unregister_mods(mods);
  173. }
  174. } else if (tap_count == ONESHOT_TAP_TOGGLE) {
  175. // Toggle Oneshot Layer
  176. #endif
  177. } else {
  178. clear_oneshot_mods();
  179. unregister_mods(mods);
  180. }
  181. }
  182. break;
  183. #endif
  184. case MODS_TAP_TOGGLE:
  185. if (event.pressed) {
  186. if (tap_count <= TAPPING_TOGGLE) {
  187. register_mods(mods);
  188. }
  189. } else {
  190. if (tap_count < TAPPING_TOGGLE) {
  191. unregister_mods(mods);
  192. }
  193. }
  194. break;
  195. default:
  196. if (event.pressed) {
  197. if (tap_count > 0) {
  198. #ifndef IGNORE_MOD_TAP_INTERRUPT
  199. if (record->tap.interrupted) {
  200. dprint("mods_tap: tap: cancel: add_mods\n");
  201. // ad hoc: set 0 to cancel tap
  202. record->tap.count = 0;
  203. register_mods(mods);
  204. } else
  205. #endif
  206. {
  207. dprint("MODS_TAP: Tap: register_code\n");
  208. register_code(action.key.code);
  209. }
  210. } else {
  211. dprint("MODS_TAP: No tap: add_mods\n");
  212. register_mods(mods);
  213. }
  214. } else {
  215. if (tap_count > 0) {
  216. dprint("MODS_TAP: Tap: unregister_code\n");
  217. unregister_code(action.key.code);
  218. } else {
  219. dprint("MODS_TAP: No tap: add_mods\n");
  220. unregister_mods(mods);
  221. }
  222. }
  223. break;
  224. }
  225. }
  226. break;
  227. #endif
  228. #ifdef EXTRAKEY_ENABLE
  229. /* other HID usage */
  230. case ACT_USAGE:
  231. switch (action.usage.page) {
  232. case PAGE_SYSTEM:
  233. if (event.pressed) {
  234. host_system_send(action.usage.code);
  235. } else {
  236. host_system_send(0);
  237. }
  238. break;
  239. case PAGE_CONSUMER:
  240. if (event.pressed) {
  241. host_consumer_send(action.usage.code);
  242. } else {
  243. host_consumer_send(0);
  244. }
  245. break;
  246. }
  247. break;
  248. #endif
  249. #ifdef MOUSEKEY_ENABLE
  250. /* Mouse key */
  251. case ACT_MOUSEKEY:
  252. if (event.pressed) {
  253. mousekey_on(action.key.code);
  254. mousekey_send();
  255. } else {
  256. mousekey_off(action.key.code);
  257. mousekey_send();
  258. }
  259. break;
  260. #endif
  261. #ifndef NO_ACTION_LAYER
  262. case ACT_LAYER:
  263. if (action.layer_bitop.on == 0) {
  264. /* Default Layer Bitwise Operation */
  265. if (!event.pressed) {
  266. uint8_t shift = action.layer_bitop.part*4;
  267. uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
  268. uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
  269. switch (action.layer_bitop.op) {
  270. case OP_BIT_AND: default_layer_and(bits | mask); break;
  271. case OP_BIT_OR: default_layer_or(bits | mask); break;
  272. case OP_BIT_XOR: default_layer_xor(bits | mask); break;
  273. case OP_BIT_SET: default_layer_and(mask); default_layer_or(bits); break;
  274. }
  275. }
  276. } else {
  277. /* Layer Bitwise Operation */
  278. if (event.pressed ? (action.layer_bitop.on & ON_PRESS) :
  279. (action.layer_bitop.on & ON_RELEASE)) {
  280. uint8_t shift = action.layer_bitop.part*4;
  281. uint32_t bits = ((uint32_t)action.layer_bitop.bits)<<shift;
  282. uint32_t mask = (action.layer_bitop.xbit) ? ~(((uint32_t)0xf)<<shift) : 0;
  283. switch (action.layer_bitop.op) {
  284. case OP_BIT_AND: layer_and(bits | mask); break;
  285. case OP_BIT_OR: layer_or(bits | mask); break;
  286. case OP_BIT_XOR: layer_xor(bits | mask); break;
  287. case OP_BIT_SET: layer_and(mask); layer_or(bits); break;
  288. }
  289. }
  290. }
  291. break;
  292. #ifndef NO_ACTION_TAPPING
  293. case ACT_LAYER_TAP:
  294. case ACT_LAYER_TAP_EXT:
  295. switch (action.layer_tap.code) {
  296. case 0xe0 ... 0xef:
  297. /* layer On/Off with modifiers(left only) */
  298. if (event.pressed) {
  299. layer_on(action.layer_tap.val);
  300. register_mods(action.layer_tap.code & 0x0f);
  301. } else {
  302. layer_off(action.layer_tap.val);
  303. unregister_mods(action.layer_tap.code & 0x0f);
  304. }
  305. break;
  306. case OP_TAP_TOGGLE:
  307. /* tap toggle */
  308. if (event.pressed) {
  309. if (tap_count < TAPPING_TOGGLE) {
  310. layer_invert(action.layer_tap.val);
  311. }
  312. } else {
  313. if (tap_count <= TAPPING_TOGGLE) {
  314. layer_invert(action.layer_tap.val);
  315. }
  316. }
  317. break;
  318. case OP_ON_OFF:
  319. event.pressed ? layer_on(action.layer_tap.val) :
  320. layer_off(action.layer_tap.val);
  321. break;
  322. case OP_OFF_ON:
  323. event.pressed ? layer_off(action.layer_tap.val) :
  324. layer_on(action.layer_tap.val);
  325. break;
  326. case OP_SET_CLEAR:
  327. event.pressed ? layer_move(action.layer_tap.val) :
  328. layer_clear();
  329. break;
  330. #ifndef NO_ACTION_ONESHOT
  331. case OP_ONESHOT:
  332. // Oneshot modifier
  333. #if defined(ONESHOT_TAP_TOGGLE) && ONESHOT_TAP_TOGGLE > 1
  334. do_release_oneshot = false;
  335. if (event.pressed) {
  336. del_mods(get_oneshot_locked_mods());
  337. if (get_oneshot_layer_state() == ONESHOT_TOGGLED) {
  338. reset_oneshot_layer();
  339. layer_off(action.layer_tap.val);
  340. break;
  341. } else if (tap_count < ONESHOT_TAP_TOGGLE) {
  342. layer_on(action.layer_tap.val);
  343. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  344. }
  345. } else {
  346. add_mods(get_oneshot_locked_mods());
  347. if (tap_count >= ONESHOT_TAP_TOGGLE) {
  348. reset_oneshot_layer();
  349. clear_oneshot_locked_mods();
  350. set_oneshot_layer(action.layer_tap.val, ONESHOT_TOGGLED);
  351. } else {
  352. clear_oneshot_layer_state(ONESHOT_PRESSED);
  353. }
  354. }
  355. #else
  356. if (event.pressed) {
  357. layer_on(action.layer_tap.val);
  358. set_oneshot_layer(action.layer_tap.val, ONESHOT_START);
  359. } else {
  360. clear_oneshot_layer_state(ONESHOT_PRESSED);
  361. if (tap_count > 1) {
  362. clear_oneshot_layer_state(ONESHOT_OTHER_KEY_PRESSED);
  363. }
  364. }
  365. #endif
  366. break;
  367. #endif
  368. default:
  369. /* tap key */
  370. if (event.pressed) {
  371. if (tap_count > 0) {
  372. dprint("KEYMAP_TAP_KEY: Tap: register_code\n");
  373. register_code(action.layer_tap.code);
  374. } else {
  375. dprint("KEYMAP_TAP_KEY: No tap: On on press\n");
  376. layer_on(action.layer_tap.val);
  377. }
  378. } else {
  379. if (tap_count > 0) {
  380. dprint("KEYMAP_TAP_KEY: Tap: unregister_code\n");
  381. unregister_code(action.layer_tap.code);
  382. } else {
  383. dprint("KEYMAP_TAP_KEY: No tap: Off on release\n");
  384. layer_off(action.layer_tap.val);
  385. }
  386. }
  387. break;
  388. }
  389. break;
  390. #endif
  391. #endif
  392. /* Extentions */
  393. #ifndef NO_ACTION_MACRO
  394. case ACT_MACRO:
  395. action_macro_play(action_get_macro(record, action.func.id, action.func.opt));
  396. break;
  397. #endif
  398. #ifdef BACKLIGHT_ENABLE
  399. case ACT_BACKLIGHT:
  400. if (!event.pressed) {
  401. switch (action.backlight.opt) {
  402. case BACKLIGHT_INCREASE:
  403. backlight_increase();
  404. break;
  405. case BACKLIGHT_DECREASE:
  406. backlight_decrease();
  407. break;
  408. case BACKLIGHT_TOGGLE:
  409. backlight_toggle();
  410. break;
  411. case BACKLIGHT_STEP:
  412. backlight_step();
  413. break;
  414. case BACKLIGHT_LEVEL:
  415. backlight_level(action.backlight.level);
  416. break;
  417. }
  418. }
  419. break;
  420. #endif
  421. case ACT_COMMAND:
  422. break;
  423. #ifndef NO_ACTION_FUNCTION
  424. case ACT_FUNCTION:
  425. action_function(record, action.func.id, action.func.opt);
  426. break;
  427. #endif
  428. default:
  429. break;
  430. }
  431. #ifndef NO_ACTION_ONESHOT
  432. /* Because we switch layers after a oneshot event, we need to release the
  433. * key before we leave the layer or no key up event will be generated.
  434. */
  435. if (do_release_oneshot && !(get_oneshot_layer_state() & ONESHOT_PRESSED ) ) {
  436. record->event.pressed = false;
  437. layer_on(get_oneshot_layer());
  438. process_record(record);
  439. layer_off(get_oneshot_layer());
  440. }
  441. #endif
  442. }
  443. /*
  444. * Utilities for actions.
  445. */
  446. void register_code(uint8_t code)
  447. {
  448. if (code == KC_NO) {
  449. return;
  450. }
  451. #ifdef LOCKING_SUPPORT_ENABLE
  452. else if (KC_LOCKING_CAPS == code) {
  453. #ifdef LOCKING_RESYNC_ENABLE
  454. // Resync: ignore if caps lock already is on
  455. if (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) return;
  456. #endif
  457. add_key(KC_CAPSLOCK);
  458. send_keyboard_report();
  459. del_key(KC_CAPSLOCK);
  460. send_keyboard_report();
  461. }
  462. else if (KC_LOCKING_NUM == code) {
  463. #ifdef LOCKING_RESYNC_ENABLE
  464. if (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) return;
  465. #endif
  466. add_key(KC_NUMLOCK);
  467. send_keyboard_report();
  468. del_key(KC_NUMLOCK);
  469. send_keyboard_report();
  470. }
  471. else if (KC_LOCKING_SCROLL == code) {
  472. #ifdef LOCKING_RESYNC_ENABLE
  473. if (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) return;
  474. #endif
  475. add_key(KC_SCROLLLOCK);
  476. send_keyboard_report();
  477. del_key(KC_SCROLLLOCK);
  478. send_keyboard_report();
  479. }
  480. #endif
  481. else if IS_KEY(code) {
  482. // TODO: should push command_proc out of this block?
  483. if (command_proc(code)) return;
  484. #ifndef NO_ACTION_ONESHOT
  485. /* TODO: remove
  486. if (oneshot_state.mods && !oneshot_state.disabled) {
  487. uint8_t tmp_mods = get_mods();
  488. add_mods(oneshot_state.mods);
  489. add_key(code);
  490. send_keyboard_report();
  491. set_mods(tmp_mods);
  492. send_keyboard_report();
  493. oneshot_cancel();
  494. } else
  495. */
  496. #endif
  497. {
  498. add_key(code);
  499. send_keyboard_report();
  500. }
  501. }
  502. else if IS_MOD(code) {
  503. add_mods(MOD_BIT(code));
  504. send_keyboard_report();
  505. }
  506. else if IS_SYSTEM(code) {
  507. host_system_send(KEYCODE2SYSTEM(code));
  508. }
  509. else if IS_CONSUMER(code) {
  510. host_consumer_send(KEYCODE2CONSUMER(code));
  511. }
  512. }
  513. void unregister_code(uint8_t code)
  514. {
  515. if (code == KC_NO) {
  516. return;
  517. }
  518. #ifdef LOCKING_SUPPORT_ENABLE
  519. else if (KC_LOCKING_CAPS == code) {
  520. #ifdef LOCKING_RESYNC_ENABLE
  521. // Resync: ignore if caps lock already is off
  522. if (!(host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK))) return;
  523. #endif
  524. add_key(KC_CAPSLOCK);
  525. send_keyboard_report();
  526. del_key(KC_CAPSLOCK);
  527. send_keyboard_report();
  528. }
  529. else if (KC_LOCKING_NUM == code) {
  530. #ifdef LOCKING_RESYNC_ENABLE
  531. if (!(host_keyboard_leds() & (1<<USB_LED_NUM_LOCK))) return;
  532. #endif
  533. add_key(KC_NUMLOCK);
  534. send_keyboard_report();
  535. del_key(KC_NUMLOCK);
  536. send_keyboard_report();
  537. }
  538. else if (KC_LOCKING_SCROLL == code) {
  539. #ifdef LOCKING_RESYNC_ENABLE
  540. if (!(host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK))) return;
  541. #endif
  542. add_key(KC_SCROLLLOCK);
  543. send_keyboard_report();
  544. del_key(KC_SCROLLLOCK);
  545. send_keyboard_report();
  546. }
  547. #endif
  548. else if IS_KEY(code) {
  549. del_key(code);
  550. send_keyboard_report();
  551. }
  552. else if IS_MOD(code) {
  553. del_mods(MOD_BIT(code));
  554. send_keyboard_report();
  555. }
  556. else if IS_SYSTEM(code) {
  557. host_system_send(0);
  558. }
  559. else if IS_CONSUMER(code) {
  560. host_consumer_send(0);
  561. }
  562. }
  563. void register_mods(uint8_t mods)
  564. {
  565. if (mods) {
  566. add_mods(mods);
  567. send_keyboard_report();
  568. }
  569. }
  570. void unregister_mods(uint8_t mods)
  571. {
  572. if (mods) {
  573. del_mods(mods);
  574. send_keyboard_report();
  575. }
  576. }
  577. void clear_keyboard(void)
  578. {
  579. clear_mods();
  580. clear_keyboard_but_mods();
  581. }
  582. void clear_keyboard_but_mods(void)
  583. {
  584. clear_weak_mods();
  585. clear_macro_mods();
  586. clear_keys();
  587. send_keyboard_report();
  588. #ifdef MOUSEKEY_ENABLE
  589. mousekey_clear();
  590. mousekey_send();
  591. #endif
  592. #ifdef EXTRAKEY_ENABLE
  593. host_system_send(0);
  594. host_consumer_send(0);
  595. #endif
  596. }
  597. bool is_tap_key(keypos_t key)
  598. {
  599. action_t action = layer_switch_get_action(key);
  600. switch (action.kind.id) {
  601. case ACT_LMODS_TAP:
  602. case ACT_RMODS_TAP:
  603. case ACT_LAYER_TAP:
  604. case ACT_LAYER_TAP_EXT:
  605. switch (action.layer_tap.code) {
  606. case 0x00 ... 0xdf:
  607. case OP_TAP_TOGGLE:
  608. case OP_ONESHOT:
  609. return true;
  610. }
  611. return false;
  612. case ACT_MACRO:
  613. case ACT_FUNCTION:
  614. if (action.func.opt & FUNC_TAP) { return true; }
  615. return false;
  616. }
  617. return false;
  618. }
  619. /*
  620. * debug print
  621. */
  622. void debug_event(keyevent_t event)
  623. {
  624. dprintf("%04X%c(%u)", (event.key.row<<8 | event.key.col), (event.pressed ? 'd' : 'u'), event.time);
  625. }
  626. void debug_record(keyrecord_t record)
  627. {
  628. debug_event(record.event);
  629. #ifndef NO_ACTION_TAPPING
  630. dprintf(":%u%c", record.tap.count, (record.tap.interrupted ? '-' : ' '));
  631. #endif
  632. }
  633. void debug_action(action_t action)
  634. {
  635. switch (action.kind.id) {
  636. case ACT_LMODS: dprint("ACT_LMODS"); break;
  637. case ACT_RMODS: dprint("ACT_RMODS"); break;
  638. case ACT_LMODS_TAP: dprint("ACT_LMODS_TAP"); break;
  639. case ACT_RMODS_TAP: dprint("ACT_RMODS_TAP"); break;
  640. case ACT_USAGE: dprint("ACT_USAGE"); break;
  641. case ACT_MOUSEKEY: dprint("ACT_MOUSEKEY"); break;
  642. case ACT_LAYER: dprint("ACT_LAYER"); break;
  643. case ACT_LAYER_TAP: dprint("ACT_LAYER_TAP"); break;
  644. case ACT_LAYER_TAP_EXT: dprint("ACT_LAYER_TAP_EXT"); break;
  645. case ACT_MACRO: dprint("ACT_MACRO"); break;
  646. case ACT_COMMAND: dprint("ACT_COMMAND"); break;
  647. case ACT_FUNCTION: dprint("ACT_FUNCTION"); break;
  648. default: dprint("UNKNOWN"); break;
  649. }
  650. dprintf("[%X:%02X]", action.kind.param>>8, action.kind.param&0xff);
  651. }