keymap.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409
  1. #include "frenchdev.h"
  2. #include "mousekey.h"
  3. #include "action.h"
  4. #include "action_layer.h"
  5. #include "keymap_extras/keymap_bepo.h"
  6. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  7. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  8. #define _BASE 0
  9. #define _SYMBOLS 1
  10. #define _MEDIA 2
  11. #define _TRNS 8
  12. #define PEDAL_DELAY 250
  13. #define KEY_DELAY 130
  14. enum macros {
  15. M_LP, // left pedal
  16. M_RP, // right pedal
  17. M_SF, // shift
  18. M_SFS, // shift and space
  19. M_L1E, // L1 and space
  20. L2INS, // L2 and insert
  21. L2LOC, // Lock L2
  22. M_UN, // undo
  23. M_CUT, // cut
  24. M_CP, // copy
  25. M_PS, // paste
  26. M_SE, // search
  27. M_SFU, // shift and underscore
  28. };
  29. static uint16_t key_timer_left_pedal;
  30. static uint16_t key_timer_right_pedal;
  31. static uint16_t key_timer_shift;
  32. static uint16_t key_timer_1;
  33. static uint16_t key_timer_2;
  34. static uint16_t shift_count = 0; //this is used to keep track of shift state and avoid inserting non breakable space
  35. static uint16_t l2_locked = 0; //this indicate wether L2 is locked
  36. #define BP_CBSP CTL_T(KC_BSPC)
  37. #define BP_CDEL CTL_T(KC_DEL)
  38. //layout : http://www.keyboard-layout-editor.com/#/gists/4480e3ab8026eb7c710a7e22203ef4aa
  39. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  40. /* base
  41. * left foot clicked is right click
  42. * left foot pressed is layer 2
  43. * right foot clicked is left click
  44. * right foot pressed is layer 1 + scroll lock (used with autohotkey for easier scrolling with trackballs)
  45. * ,------. .. ,------. *
  46. * ,------| F3 |-------------. .. ,-------------| F10 |------. *
  47. * ,------| F2 |------| F4 | F5 |------. .. ,------| F8 | F9 |------| F11 |------. *
  48. * | F1 |------| »/3 |------|------| F6 | .. | F7 |------|------| -/8 |------| F12 | *
  49. * ,------+------| «/2 |------| (/4 | )/5 |------| .. |------| @/6 | +/7 |------| //9 |------+------. *
  50. * | ESC | "/1 |------| O |------|------| ¨ | .. | ^ |------|------| D |------| * /0 |BCKSP | *
  51. * |------+------| É |------| P | È |------| .. |------| K | V |------| L |------+------| *
  52. * | TAB | B |------| E |------|------| _ | .. | =/° |------|------| S |------| J |ENTER | *
  53. * |------+------| U |------| I | F |------| .. |------| C | T |------| R |------+------| *
  54. * | ` | A |------| Y |------|------| ; | .. | ! |------|------| UP |------| N | '/? | *
  55. * |------+------| À |------| X | W |------|-------------. .. .-------------|------| M | G |------| H |------+------| *
  56. * | SHIFT| Z |------| . |------|------|sp/sh |bsp/ct|L2/ins| .. |L2lock|del/CT|sp/sh |------|------| DOWN |------| Q |SHIFT | *
  57. * |------+------| / |------| , | space|------|------|------ .. ------|------|------| L1/sp| LEFT |------| UP |------+------| *
  58. * | CTRL | win |------/ \-------------| L1 | alt | .. | CAPS | L1 |-------------/ \------| : | CTRL | *
  59. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  60. *M(M_LP)
  61. */
  62. [_BASE] = KEYMAP(
  63. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  64. KC_ESC, BP_DQOT, BP_LGIL, BP_RGIL, BP_LPRN, BP_RPRN, BP_DTRM, BP_DCRC, BP_AT, BP_PLUS, BP_MINS, BP_SLSH, BP_ASTR, KC_BSPC, \
  65. KC_TAB, BP_B, BP_ECUT, BP_O, BP_P, BP_EGRV, BP_UNDS, BP_EQL, BP_K, BP_V, BP_D, BP_L, BP_J, KC_ENT, \
  66. BP_GRV, BP_A, BP_U, BP_E, BP_I, BP_F, BP_SCLN, BP_EXLM, BP_C, BP_T, BP_S, BP_R, BP_N, BP_APOS, \
  67. M(M_SF), BP_Z, BP_AGRV, BP_Y, BP_X, BP_W, M(M_SFS), BP_CBSP, M(L2INS), M(L2LOC), BP_CDEL, M(M_SFS),BP_M, BP_G, KC_UP, BP_H, BP_Q, M(M_SF), \
  68. KC_LCTL, KC_LGUI, KC_PSLS, BP_DOT, BP_COMM, KC_SPACE,M(M_L1E), KC_LALT, KC_CAPS, M(M_L1E),KC_SPACE,KC_LEFT, KC_DOWN, KC_RIGHT,BP_COLN, KC_RCTL, \
  69. //left pedals
  70. M(M_LP), M(M_RP), KC_TRNS, \
  71. //right pedals
  72. M(M_LP), M(M_RP), KC_TRNS \
  73. ),
  74. /* Larer 1 for symbols.
  75. * left foot is middle click
  76. * ,------. .. ,------. *
  77. * ,------| |-------------. .. ,-------------| |------. *
  78. * ,------| |------| | |------. .. ,------| | |------| |------. *
  79. * | |------| § |------|------| | .. | |------|------| ± |------| | *
  80. * ,------+------| ¶ |------| µ | |------| .. |------| ≤ | ≥ |------| ÷ |------+------. *
  81. * | | ¤ |------| { |------|------| ~ | .. | ˇ |------|------| ] |------| × | | *
  82. * |------+------| * |------| } | ` |------| .. |------| # | [ |------| % |------+------| *
  83. * | | \ |------| ( |------|------| | .. | ≠ |------|------| > |------| ‰ | | *
  84. * |------+------| Ù |------| ) | + |------| .. |------| Ç | < |------| & |------+------| *
  85. * | | = |------| copy |------|------| : | .. | ? |------|------| PGUP |------| _ | | *
  86. * |------+------| cut |------| paste|search|------|-------------. .. .-------------|------| $ | = |------| | |------+------| *
  87. * | | undo |------| \ |------|------| | | | .. | | | |------|------| PGDN |------| / | | *
  88. * |------+------| |------| | |------|------|------ .. ------|------|------| | HOME |------| PGDN |------+------| *
  89. * | | |------/ \-------------| | | .. | | |-------------/ \------| | | *
  90. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  91. *
  92. */
  93. [_SYMBOLS] = KEYMAP(
  94. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  95. KC_TRNS, BP_DCUR, BP_PARG, BP_SECT, BP_DGRK, KC_TRNS, BP_TILD, BP_DCAR, BP_LEQL, BP_GEQL, BP_PSMS, BP_OBEL, BP_TIMS, KC_TRNS, \
  96. KC_TRNS, BP_BSLS, BP_ASTR, BP_LCBR, BP_RCBR, BP_GRV, KC_TRNS, BP_DIFF, BP_HASH, BP_LBRC, BP_RBRC, BP_PERC, BP_PMIL, KC_TRNS, \
  97. KC_TRNS, BP_EQL, BP_UGRV, BP_LPRN, BP_RPRN, BP_PLUS, BP_COLN, BP_QEST, BP_CCED, BP_LESS, BP_GRTR, BP_AMPR, BP_UNDS, KC_TRNS, \
  98. KC_TRNS, M(M_UN), M(M_CUT),M(M_CP), M(M_PS), M(M_SE), KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, BP_DLR, BP_EQL, KC_PGUP, BP_PIPE, BP_SLSH, KC_TRNS, \
  99. KC_TRNS, KC_TRNS, BP_BSLS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_HOME, KC_PGDN, KC_END, KC_TRNS, KC_TRNS, \
  100. //left pedals
  101. KC_TRNS, KC_BTN1, KC_TRNS, \
  102. //right pedals
  103. KC_TRNS, KC_BTN1, KC_TRNS \
  104. ),
  105. /* MEDIA, mouse and numpad.
  106. * right pedal is left clic
  107. * ,------. .. ,------. *
  108. * ,------|PAUSE |-------------. .. ,-------------| PRINT|------. *
  109. * ,------|SCROLL|------|MUTE |VOLUD |------. .. ,------| pre | next |------| calc |------. *
  110. * |RESET |------| stop |------|------|VOLDU | .. | play |------|------| stop |------| num | *
  111. * ,------+------| |------| pre | next |------| .. |------| pre | next |------| |------+------. *
  112. * | | |------|scrolu|------|------| play | .. | play |------|------| 8 |------| - | | *
  113. * |------+------| |------| | bt4 |------| .. |------| next | 7 |------| 9 |------+------| *
  114. * | | |------|scrold|------|------| bt5 | .. | pre |------|------| 5 |------| + | | *
  115. * |------+------| |------|mclic | rclic|------| .. |------| rclic| 4 |------| 6 |------+------| *
  116. * | | |------| |------|------| lclic| .. | lclic|------|------| 2 |------| * | | *
  117. * |------+------| |------| | mclck|------|-------------. .. .-------------|------| mclic| 1 |------| 3 |------+------| *
  118. * | | |------| |------|------| | | | .. | | | |------|------| num. |------| / | | *
  119. * |------+------| |------| | |------|------|------ .. ------|------|------| | 0 |------| . |------+------| *
  120. * | | |------/ \-------------| | | .. | | |-------------/ \------| , | | *
  121. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  122. *
  123. */
  124. [_MEDIA] = KEYMAP(
  125. RESET, KC_SLCK, KC_PAUS, KC_MUTE, KC_VOLD, KC_VOLU, KC_MUTE, KC_VOLD, KC_VOLU, KC_PSCR, KC_CALC, KC_NLCK, \
  126. KC_TRNS, KC_TRNS, KC_TRNS, KC_MSTP, KC_MPRV, KC_MNXT, KC_MPLY, KC_MPLY, KC_MPRV, KC_MNXT, KC_MSTP, KC_TRNS, KC_PMNS, KC_TRNS, \
  127. KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_U, KC_TRNS, KC_BTN4, KC_BTN5, KC_BTN4, KC_BTN5, KC_KP_7, KC_KP_8, KC_KP_9, KC_PPLS, KC_TRNS, \
  128. KC_TRNS, KC_TRNS, KC_TRNS, KC_WH_D, KC_BTN3, KC_BTN2, KC_BTN1, KC_BTN1, KC_BTN2, KC_KP_4, KC_KP_5, KC_KP_6, KC_PAST, KC_TRNS, \
  129. KC_TRNS, M(M_UN), M(M_CUT),M(M_CP), M(M_PS), KC_BTN3, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_BTN3, KC_KP_1, KC_KP_2, KC_KP_3, KC_PSLS, KC_TRNS, \
  130. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_KP_0, KC_PDOT, BP_DOT, BP_COMM, KC_TRNS, \
  131. //left pedals
  132. KC_BTN3, M(M_RP), KC_TRNS, \
  133. //right pedals
  134. KC_BTN3, M(M_RP), KC_TRNS \
  135. ),
  136. /* TRNS - skeleton for laters
  137. * ,------. .. ,------. *
  138. * ,------| |-------------. .. ,-------------| |------. *
  139. * ,------| |------| | |------. .. ,------| | |------| |------. *
  140. * | |------| |------|------| | .. | |------|------| |------| | *
  141. * ,------+------| |------| | |------| .. |------| | |------| |------+------. *
  142. * | | |------| |------|------| | .. | |------|------| |------| | | *
  143. * |------+------| |------| | |------| .. |------| | |------| |------+------| *
  144. * | | |------| |------|------| | .. | |------|------| |------| | | *
  145. * |------+------| |------| | |------| .. |------| | |------| |------+------| *
  146. * | | |------| |------|------| | .. | |------|------| |------| | | *
  147. * |------+------| |------| | |------|-------------. .. .-------------|------| | |------| |------+------| *
  148. * | | |------| |------|------| | | | .. | | | |------|------| |------| | | *
  149. * |------+------| |------| | |------|------|------ .. ------|------|------| | |------| |------+------| *
  150. * | | |------/ \-------------| | | .. | | |-------------/ \------| | | *
  151. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  152. *
  153. */
  154. [_TRNS] = KEYMAP(
  155. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  156. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  157. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  158. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  159. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  160. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  161. //left pedals
  162. KC_BTN3, M(M_RP), KC_TRNS, \
  163. //right pedals
  164. KC_BTN3, M(M_RP), KC_TRNS \
  165. ),
  166. };
  167. const uint16_t PROGMEM fn_actions[] = {
  168. };
  169. void hold_shift(void) {
  170. shift_count = shift_count + 1;
  171. register_code(KC_LSHIFT);
  172. }
  173. void release_shift(void) {
  174. shift_count = shift_count - 1;
  175. if(shift_count <= 0){
  176. unregister_code(KC_LSHIFT);
  177. shift_count = 0;
  178. }
  179. }
  180. void press_space(void) {
  181. if(shift_count > 0) unregister_code (KC_LSHIFT);
  182. register_code (KC_SPACE);
  183. unregister_code (KC_SPACE);
  184. if(shift_count > 0) register_code (KC_LSHIFT);
  185. }
  186. void press_enter(void) {
  187. if(shift_count > 0) unregister_code (KC_LSHIFT);
  188. register_code (KC_ENT);
  189. unregister_code (KC_ENT);
  190. if(shift_count > 0) register_code (KC_LSHIFT);
  191. }
  192. void press_underscore(void) {
  193. if(shift_count > 0) unregister_code (KC_LSHIFT);
  194. register_code ((unsigned char) BP_UNDS);
  195. unregister_code ((unsigned char) BP_UNDS);
  196. if(shift_count > 0) register_code (KC_LSHIFT);
  197. }
  198. const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt)
  199. {
  200. switch(id) {
  201. case M_LP: //left pedal
  202. if (record->event.pressed) {
  203. layer_on(1);
  204. register_code (KC_SLCK);
  205. key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer.
  206. } else {
  207. if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) {
  208. mousekey_on (KC_BTN2);
  209. mousekey_send();
  210. mousekey_off (KC_BTN2);
  211. mousekey_send();
  212. }
  213. unregister_code (KC_SLCK);
  214. layer_off(1);
  215. }
  216. break;
  217. case M_RP: //right pedal
  218. if (record->event.pressed) {
  219. layer_on(2);
  220. key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer.
  221. } else {
  222. if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) {
  223. mousekey_on (KC_BTN1);
  224. mousekey_send();
  225. mousekey_off (KC_BTN1);
  226. mousekey_send();
  227. }
  228. layer_off(2);
  229. }
  230. break;
  231. case M_SF: // shift, using macro to keep track of shift state and avoid inserting nbsp by mistake
  232. if (record->event.pressed) {
  233. hold_shift();
  234. } else {
  235. release_shift();
  236. }
  237. break;
  238. case M_SFS: // shift when held, space when tapped
  239. if (record->event.pressed) {
  240. hold_shift();
  241. key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
  242. } else {
  243. if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
  244. press_space();
  245. }
  246. release_shift();
  247. }
  248. break;
  249. case M_SFU: // shift when held, _ when tapped
  250. if (record->event.pressed) {
  251. hold_shift();
  252. key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
  253. } else {
  254. if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
  255. press_space();
  256. }
  257. release_shift();
  258. }
  259. break;
  260. case M_L1E: // L1 when held, space when tapped
  261. if (record->event.pressed) {
  262. layer_on(1);
  263. key_timer_1 = timer_read(); // if the key is being pressed, we start the timer.
  264. } else {
  265. if (timer_elapsed(key_timer_1) < KEY_DELAY) {
  266. press_enter();
  267. }
  268. layer_off(1);
  269. }
  270. break;
  271. case L2INS: //activate layer 2, if released before 100ms trigger INS. basicaly equivalent to LT(2, KC_INS) but without delay for activation of layer 2
  272. if (record->event.pressed) {
  273. layer_on(2);
  274. key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
  275. } else {
  276. if (timer_elapsed(key_timer_2) < KEY_DELAY) {
  277. register_code (KC_INS);
  278. unregister_code (KC_INS);
  279. }
  280. l2_locked = 0;
  281. layer_off(2);
  282. }
  283. break;
  284. case L2LOC: //lock L2
  285. if (record->event.pressed) {
  286. key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
  287. layer_on(2);
  288. } else {
  289. if (timer_elapsed(key_timer_2) < KEY_DELAY && l2_locked == 0) {
  290. l2_locked = 1;
  291. layer_on(2);
  292. } else {
  293. l2_locked = 0;
  294. layer_off(2);
  295. }
  296. }
  297. break;
  298. case M_UN: // undo
  299. if (record->event.pressed) {
  300. register_code(KC_LCTL);
  301. register_code(BP_Z);
  302. unregister_code(BP_Z);
  303. unregister_code(KC_LCTL);
  304. }
  305. break;
  306. case M_CUT: // cut
  307. if (record->event.pressed) {
  308. register_code(KC_LCTL);
  309. register_code(BP_X);
  310. unregister_code(BP_X);
  311. unregister_code(KC_LCTL);
  312. }
  313. break;
  314. case M_CP: // copy
  315. if (record->event.pressed) {
  316. register_code(KC_LCTL);
  317. register_code(BP_C);
  318. unregister_code(BP_C);
  319. unregister_code(KC_LCTL);
  320. }
  321. break;
  322. case M_PS: // paste
  323. if (record->event.pressed) {
  324. register_code(KC_LCTL);
  325. register_code(BP_V);
  326. unregister_code(BP_V);
  327. unregister_code(KC_LCTL);
  328. }
  329. break;
  330. case M_SE: // search
  331. if (record->event.pressed) {
  332. register_code(KC_LCTL);
  333. register_code(BP_F);
  334. unregister_code(BP_F);
  335. unregister_code(KC_LCTL);
  336. }
  337. break;
  338. }
  339. return MACRO_NONE;
  340. };
  341. void action_function(keyrecord_t *record, uint8_t id, uint8_t opt) {
  342. }
  343. void matrix_init_user(void) {
  344. }
  345. // Bleah globals need to be initialized.
  346. uint8_t old_layer=_BASE;
  347. void matrix_scan_user(void) {
  348. uint8_t layer = biton32(layer_state);
  349. ergodox_right_led_1_off();
  350. ergodox_right_led_2_off();
  351. switch (layer) {
  352. case _BASE:
  353. ergodox_right_led_2_on();
  354. break;
  355. case _SYMBOLS:
  356. ergodox_right_led_1_on();
  357. break;
  358. case _MEDIA:
  359. ergodox_right_led_1_on();
  360. ergodox_right_led_2_on();
  361. default:
  362. // none
  363. break;
  364. }
  365. }
  366. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  367. return true;
  368. }
  369. void led_set_user(uint8_t usb_led) {
  370. if (usb_led & (1<<USB_LED_CAPS_LOCK)){
  371. ergodox_right_led_3_on();
  372. } else {
  373. ergodox_right_led_3_off();
  374. }
  375. return ;
  376. }