keymap.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. #include QMK_KEYBOARD_H
  2. #include "keymap_bepo.h"
  3. // Each layer gets a name for readability, which is then used in the keymap matrix below.
  4. // The underscores don't mean anything - you can have a layer called STUFF or any other name.
  5. #define _BASE 0
  6. #define _SYMBOLS 1
  7. #define _MEDIA 2
  8. #define _TRNS 8
  9. #define PEDAL_DELAY 250
  10. #define KEY_DELAY 130
  11. enum custom_keycodes {
  12. M_LP = SAFE_RANGE, // left pedal
  13. M_RP, // right pedal
  14. M_SF, // shift
  15. M_SFS, // shift and space
  16. M_L1E, // L1 and space
  17. L2INS, // L2 and insert
  18. L2LOC, // Lock L2
  19. M_UN, // undo
  20. M_CUT, // cut
  21. M_CP, // copy
  22. M_PS, // paste
  23. M_SE, // search
  24. M_SFU, // shift and underscore
  25. };
  26. static uint16_t key_timer_left_pedal;
  27. static uint16_t key_timer_right_pedal;
  28. static uint16_t key_timer_shift;
  29. static uint16_t key_timer_1;
  30. static uint16_t key_timer_2;
  31. static uint16_t shift_count = 0; //this is used to keep track of shift state and avoid inserting non breakable space
  32. static uint16_t l2_locked = 0; //this indicate wether L2 is locked
  33. #define BP_CBSP CTL_T(KC_BSPC)
  34. #define BP_CDEL CTL_T(KC_DEL)
  35. //layout : http://www.keyboard-layout-editor.com/#/gists/4480e3ab8026eb7c710a7e22203ef4aa
  36. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  37. /* base
  38. * left foot clicked is right click
  39. * left foot pressed is layer 2
  40. * right foot clicked is left click
  41. * right foot pressed is layer 1 + scroll lock (used with autohotkey for easier scrolling with trackballs)
  42. * ,------. .. ,------. *
  43. * ,------| F3 |-------------. .. ,-------------| F10 |------. *
  44. * ,------| F2 |------| F4 | F5 |------. .. ,------| F8 | F9 |------| F11 |------. *
  45. * | F1 |------| »/3 |------|------| F6 | .. | F7 |------|------| -/8 |------| F12 | *
  46. * ,------+------| «/2 |------| (/4 | )/5 |------| .. |------| @/6 | +/7 |------| //9 |------+------. *
  47. * | ESC | "/1 |------| O |------|------| ¨ | .. | ^ |------|------| D |------| * /0 |BCKSP | *
  48. * |------+------| É |------| P | È |------| .. |------| K | V |------| L |------+------| *
  49. * | TAB | B |------| E |------|------| _ | .. | =/° |------|------| S |------| J |ENTER | *
  50. * |------+------| U |------| I | F |------| .. |------| C | T |------| R |------+------| *
  51. * | ` | A |------| Y |------|------| ; | .. | ! |------|------| UP |------| N | '/? | *
  52. * |------+------| À |------| X | W |------|-------------. .. .-------------|------| M | G |------| H |------+------| *
  53. * | SHIFT| Z |------| . |------|------|sp/sh |bsp/ct|L2/ins| .. |L2lock|del/CT|sp/sh |------|------| DOWN |------| Q |SHIFT | *
  54. * |------+------| / |------| , | space|------|------|------ .. ------|------|------| L1/sp| LEFT |------| UP |------+------| *
  55. * | CTRL | win |------/ \-------------| L1 | alt | .. | CAPS | L1 |-------------/ \------| : | CTRL | *
  56. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  57. */
  58. [_BASE] = LAYOUT(
  59. KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, \
  60. 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, \
  61. 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, \
  62. 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, \
  63. M_SF, BP_Z, BP_AGRV, BP_Y, BP_X, KC_RBRC, M_SFS, BP_CBSP, L2INS, L2LOC, BP_CDEL, M_SFS, BP_M, BP_G, KC_UP, BP_H, BP_Q, M_SF, \
  64. KC_LCTL, KC_LGUI, KC_PSLS, BP_DOT, BP_COMM, KC_SPACE,M_L1E, KC_LALT, KC_CAPS, M_L1E, KC_SPACE, KC_LEFT, KC_DOWN, KC_RIGHT,BP_COLN, KC_RCTL, \
  65. //left pedals
  66. M_LP, M_RP, KC_TRNS, \
  67. //right pedals
  68. M_LP, M_RP, KC_TRNS \
  69. ),
  70. /* Larer 1 for symbols.
  71. * left foot is middle click
  72. * ,------. .. ,------. *
  73. * ,------| |-------------. .. ,-------------| |------. *
  74. * ,------| |------| | |------. .. ,------| | |------| |------. *
  75. * | |------| § |------|------| | .. | |------|------| ± |------| | *
  76. * ,------+------| ¶ |------| µ | |------| .. |------| ≤ | ≥ |------| ÷ |------+------. *
  77. * | | ¤ |------| { |------|------| ~ | .. | ˇ |------|------| ] |------| × | | *
  78. * |------+------| * |------| } | ` |------| .. |------| # | [ |------| % |------+------| *
  79. * | | \ |------| ( |------|------| | .. | ≠ |------|------| > |------| ‰ | | *
  80. * |------+------| Ù |------| ) | + |------| .. |------| Ç | < |------| & |------+------| *
  81. * | | = |------| copy |------|------| : | .. | ? |------|------| PGUP |------| _ | | *
  82. * |------+------| cut |------| paste|search|------|-------------. .. .-------------|------| $ | = |------| | |------+------| *
  83. * | | undo |------| \ |------|------| | | | .. | | | |------|------| PGDN |------| / | | *
  84. * |------+------| |------| | |------|------|------ .. ------|------|------| | HOME |------| PGDN |------+------| *
  85. * | | |------/ \-------------| | | .. | | |-------------/ \------| | | *
  86. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  87. *
  88. */
  89. [_SYMBOLS] = LAYOUT(
  90. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  91. 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, \
  92. 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, \
  93. 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, \
  94. KC_TRNS, M_UN, M_CUT, M_CP, M_PS, 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, \
  95. 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, \
  96. //left pedals
  97. KC_TRNS, KC_BTN1, KC_TRNS, \
  98. //right pedals
  99. KC_TRNS, KC_BTN1, KC_TRNS \
  100. ),
  101. /* MEDIA, mouse and numpad.
  102. * right pedal is left clic
  103. * ,------. .. ,------. *
  104. * ,------|PAUSE |-------------. .. ,-------------| PRINT|------. *
  105. * ,------|SCROLL|------|MUTE |VOLUD |------. .. ,------| pre | next |------| calc |------. *
  106. * |RESET |------| stop |------|------|VOLDU | .. | play |------|------| stop |------| num | *
  107. * ,------+------| |------| pre | next |------| .. |------| pre | next |------| |------+------. *
  108. * | | |------|scrolu|------|------| play | .. | play |------|------| 8 |------| - | | *
  109. * |------+------| |------| | bt4 |------| .. |------| next | 7 |------| 9 |------+------| *
  110. * | | |------|scrold|------|------| bt5 | .. | pre |------|------| 5 |------| + | | *
  111. * |------+------| |------|mclic | rclic|------| .. |------| rclic| 4 |------| 6 |------+------| *
  112. * | | |------| |------|------| lclic| .. | lclic|------|------| 2 |------| * | | *
  113. * |------+------| |------| | mclck|------|-------------. .. .-------------|------| mclic| 1 |------| 3 |------+------| *
  114. * | | |------| |------|------| | | | .. | | | |------|------| num. |------| / | | *
  115. * |------+------| |------| | |------|------|------ .. ------|------|------| | 0 |------| . |------+------| *
  116. * | | |------/ \-------------| | | .. | | |-------------/ \------| , | | *
  117. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  118. *
  119. */
  120. [_MEDIA] = LAYOUT(
  121. RESET, KC_SLCK, KC_PAUS, KC_MUTE, KC_VOLD, KC_VOLU, KC_MUTE, KC_VOLD, KC_VOLU, KC_PSCR, KC_CALC, KC_NLCK, \
  122. 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, \
  123. 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, \
  124. 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, \
  125. KC_TRNS, M_UN, M_CUT, M_CP, 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, \
  126. 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, \
  127. //left pedals
  128. KC_BTN3, M_RP, KC_TRNS, \
  129. //right pedals
  130. KC_BTN3, M_RP, KC_TRNS \
  131. ),
  132. /* TRNS - skeleton for laters
  133. * ,------. .. ,------. *
  134. * ,------| |-------------. .. ,-------------| |------. *
  135. * ,------| |------| | |------. .. ,------| | |------| |------. *
  136. * | |------| |------|------| | .. | |------|------| |------| | *
  137. * ,------+------| |------| | |------| .. |------| | |------| |------+------. *
  138. * | | |------| |------|------| | .. | |------|------| |------| | | *
  139. * |------+------| |------| | |------| .. |------| | |------| |------+------| *
  140. * | | |------| |------|------| | .. | |------|------| |------| | | *
  141. * |------+------| |------| | |------| .. |------| | |------| |------+------| *
  142. * | | |------| |------|------| | .. | |------|------| |------| | | *
  143. * |------+------| |------| | |------|-------------. .. .-------------|------| | |------| |------+------| *
  144. * | | |------| |------|------| | | | .. | | | |------|------| |------| | | *
  145. * |------+------| |------| | |------|------|------ .. ------|------|------| | |------| |------+------| *
  146. * | | |------/ \-------------| | | .. | | |-------------/ \------| | | *
  147. * `-------------/ \-------------/ .. \-------------/ \-------------/ *
  148. *
  149. */
  150. [_TRNS] = LAYOUT(
  151. KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, KC_TRNS, \
  152. 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, \
  153. 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, \
  154. 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, \
  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, 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, KC_TRNS, KC_TRNS, \
  157. //left pedals
  158. KC_BTN3, M_RP, KC_TRNS, \
  159. //right pedals
  160. KC_BTN3, M_RP, KC_TRNS \
  161. ),
  162. };
  163. void hold_shift(void) {
  164. shift_count = shift_count + 1;
  165. register_code(KC_LSHIFT);
  166. }
  167. void release_shift(void) {
  168. shift_count = shift_count - 1;
  169. if(shift_count <= 0){
  170. unregister_code(KC_LSHIFT);
  171. shift_count = 0;
  172. }
  173. }
  174. void press_space(void) {
  175. if(shift_count > 0) unregister_code (KC_LSHIFT);
  176. tap_code(KC_SPACE);
  177. if(shift_count > 0) register_code (KC_LSHIFT);
  178. }
  179. void press_enter(void) {
  180. if(shift_count > 0) unregister_code (KC_LSHIFT);
  181. tap_code (KC_ENT);
  182. if(shift_count > 0) register_code (KC_LSHIFT);
  183. }
  184. void press_underscore(void) {
  185. if(shift_count > 0) unregister_code (KC_LSHIFT);
  186. tap_code ((unsigned char) BP_UNDS);
  187. if(shift_count > 0) register_code (KC_LSHIFT);
  188. }
  189. void matrix_init_user(void) {
  190. }
  191. // Bleah globals need to be initialized.
  192. uint8_t old_layer=_BASE;
  193. void matrix_scan_user(void) {
  194. uint8_t layer = biton32(layer_state);
  195. frenchdev_led_1_off();
  196. frenchdev_led_2_off();
  197. switch (layer) {
  198. case _BASE:
  199. frenchdev_led_2_on();
  200. break;
  201. case _SYMBOLS:
  202. frenchdev_led_1_on();
  203. break;
  204. case _MEDIA:
  205. frenchdev_led_1_on();
  206. frenchdev_led_2_on();
  207. default:
  208. // none
  209. break;
  210. }
  211. }
  212. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  213. switch(keycode) {
  214. case M_LP: //left pedal
  215. if (record->event.pressed) {
  216. layer_on(1);
  217. register_code (KC_SLCK);
  218. key_timer_left_pedal = timer_read(); // if the key is being pressed, we start the timer.
  219. } else {
  220. if (timer_elapsed(key_timer_left_pedal) < KEY_DELAY) {
  221. tap_code (KC_BTN2);
  222. }
  223. unregister_code (KC_SLCK);
  224. layer_off(1);
  225. }
  226. break;
  227. case M_RP: //right pedal
  228. if (record->event.pressed) {
  229. layer_on(2);
  230. key_timer_right_pedal = timer_read(); // if the key is being pressed, we start the timer.
  231. } else {
  232. if (timer_elapsed(key_timer_right_pedal) < PEDAL_DELAY) {
  233. tap_code (KC_BTN1);
  234. }
  235. layer_off(2);
  236. }
  237. break;
  238. case M_SF: // shift, using macro to keep track of shift state and avoid inserting nbsp by mistake
  239. if (record->event.pressed) {
  240. hold_shift();
  241. } else {
  242. release_shift();
  243. }
  244. break;
  245. case M_SFS: // shift when held, space when tapped
  246. if (record->event.pressed) {
  247. hold_shift();
  248. key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
  249. } else {
  250. if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
  251. press_space();
  252. }
  253. release_shift();
  254. }
  255. break;
  256. case M_SFU: // shift when held, _ when tapped
  257. if (record->event.pressed) {
  258. hold_shift();
  259. key_timer_shift = timer_read(); // if the key is being pressed, we start the timer.
  260. } else {
  261. if (timer_elapsed(key_timer_shift) < KEY_DELAY) {
  262. press_space();
  263. }
  264. release_shift();
  265. }
  266. break;
  267. case M_L1E: // L1 when held, space when tapped
  268. if (record->event.pressed) {
  269. layer_on(1);
  270. key_timer_1 = timer_read(); // if the key is being pressed, we start the timer.
  271. } else {
  272. if (timer_elapsed(key_timer_1) < KEY_DELAY) {
  273. press_enter();
  274. }
  275. layer_off(1);
  276. }
  277. break;
  278. 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
  279. if (record->event.pressed) {
  280. layer_on(2);
  281. key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
  282. } else {
  283. if (timer_elapsed(key_timer_2) < KEY_DELAY) {
  284. tap_code (KC_INS);
  285. }
  286. l2_locked = 0;
  287. layer_off(2);
  288. }
  289. break;
  290. case L2LOC: //lock L2
  291. if (record->event.pressed) {
  292. key_timer_2 = timer_read(); // if the key is being pressed, we start the timer.
  293. layer_on(2);
  294. } else {
  295. if (timer_elapsed(key_timer_2) < KEY_DELAY && l2_locked == 0) {
  296. l2_locked = 1;
  297. layer_on(2);
  298. } else {
  299. l2_locked = 0;
  300. layer_off(2);
  301. }
  302. }
  303. break;
  304. case M_UN: // undo
  305. if (record->event.pressed) {
  306. tap_code16(C(BP_Z));
  307. }
  308. break;
  309. case M_CUT: // cut
  310. if (record->event.pressed) {
  311. tap_code16(C(BP_X));
  312. }
  313. break;
  314. case M_CP: // copy
  315. if (record->event.pressed) {
  316. tap_code16(C(BP_C));
  317. }
  318. break;
  319. case M_PS: // paste
  320. if (record->event.pressed) {
  321. tap_code16(C(BP_V));
  322. }
  323. break;
  324. case M_SE: // search
  325. if (record->event.pressed) {
  326. tap_code16(C(BP_F));
  327. }
  328. break;
  329. }
  330. return true;
  331. }
  332. void led_set_user(uint8_t usb_led) {
  333. if (usb_led & (1<<USB_LED_CAPS_LOCK)){
  334. frenchdev_led_3_on();
  335. } else {
  336. frenchdev_led_3_off();
  337. }
  338. return ;
  339. }