keymap.c 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. #include QMK_KEYBOARD_H
  2. #include <keycodes.h>
  3. // Implement Super-alt↯tab
  4. // See https://docs.qmk.fm/#/feature_macros?id=super-alt↯tab
  5. bool is_alt_tab_active = false;
  6. uint16_t alt_tab_timer = 0;
  7. // Defining all the custom keycodes.
  8. enum custom_keycodes {
  9. ALT_TAB = SAFE_RANGE,
  10. SLC_ROW,
  11. SLC_ALL,
  12. SLC_WRD
  13. };
  14. const uint16_t PROGMEM lock_combo[] = {KC_J, KC_K, KC_L, KC_SCLN, COMBO_END};
  15. combo_t key_combos[COMBO_COUNT] = {COMBO(lock_combo, LGUI(KC_O))};
  16. // Define the keycodes for one qwerty layer and one Fn layer.
  17. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  18. /* 0: qwerty
  19. * ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬─────────────┐
  20. * │ ` Esc│ 1 │ 2 │ 3 │ 4 │ 5 │ 6 │ 7 │ 8 │ 9 │ 0 │ - │ = │ Bksp │
  21. * ├──────┴──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼─────┬───────┤
  22. * │ Tab │ Q │ W │ E │ R │ T │ Y │ U │ I │ O │ P │ [ │ ] │ │
  23. * ├─────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼─────┴┐ Enter│
  24. * │ Layer 2 │ A │ S │ D │ F │ G │ H │ J │ K │ L │ ; │ ' │ # │ │
  25. * ├──────┬──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┴──────┴──────┤
  26. * │ Shift│ \ │ Z │ X │ C │ V │ B │ N │ M │ , │ . │ / │ Shift │
  27. * ├──────┼──────┼──────┼──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┼──────┬──────┬──────┤
  28. * │ Ctrl │ Alt │↯ATab │ Space │ Gui │ Alt │ Ctrl │
  29. * └──────┴──────┴──────┴──────────────────────────────────────────────────────────────┴──────┴──────┴──────┘
  30. *
  31. * Hidden features : 
  32. * - Left Shift is also Home on a single tap.
  33. * - Left Ctrl is also End on a single tap.
  34. * - Right Shift is also page-up on a single tap.
  35. * - Right Ctrl is also page-down on a single tap.
  36. * - Press JKLM for Windows + L (Session lock)
  37. */
  38. [0] = LAYOUT( \
  39. KC_GESC , KC_1 , KC_2 , KC_3 , KC_4 , KC_5 , KC_6 , KC_7 , KC_8 , KC_9 , KC_0 , KC_MINS, KC_EQL , KC_BSPC,
  40. KC_TAB , KC_Q , KC_W , KC_E , KC_R , KC_T , KC_Y , KC_U , KC_I , KC_O , KC_P , KC_LBRC, KC_RBRC,
  41. MO(1) , KC_A , KC_S , KC_D , KC_F , KC_G , KC_H , KC_J , KC_K , KC_L , KC_SCLN, KC_QUOT, KC_NUHS, KC_ENT ,
  42. KC_LSPO , KC_NUBS, KC_Z , KC_X , KC_C , KC_V , KC_B , KC_N , KC_M , KC_COMM, KC_DOT , KC_SLSH, KC_RSPC ,
  43. KC_LCPO , KC_LGUI, KC_LALT, KC_SPC, KC_APP , KC_RALT, KC_RCPC
  44. ),
  45. /* 1: second layer for media keys and many advanced features ç
  46. * ┌──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬──────┬─────────────┐
  47. * │Alt F4│ F1 │ F2 │ F3 │ F4 │ F5 │ F6 │ F7 │ F8 │ F9 │ F10 │ F11 │ F12 │ │
  48. * ├──────┴──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼─────┬───────┤
  49. * │ │ │PrtScn│ Brt+ │ Brt- │Ctrl A│ Home │ Up │ End │ ‽  │ ↑     │ ⸮   │ │ │
  50. * ├─────────────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼─────┴┐ │
  51. * │ │ Cut │ Copy │Paste │ Del │ Del │ Left │ Down │Right │ ← │ ↓ │ → │ │ │
  52. * ├──────┬──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┼──────┴──────┴──────┤
  53. * │ │ │ Mute │ Vol- │ Vol+ │ │ │ │ │ │ │Reset │ │
  54. * ├──────┼──────┼──────┼──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┴──────┼──────┬──────┬──────┤
  55. * │ │ │ │ │ │ │ │
  56. * └──────┴──────┴──────┴──────────────────────────────────────────────────────────────┴──────┴──────┴──────┘
  57. */
  58. [1] = LAYOUT( \
  59. LALT(KC_F4), KC_F1 , KC_F2 , KC_F3 , KC_F4 , KC_F5 , KC_F6 , KC_F7 , KC_F8 , KC_F9 , KC_F10 , KC_F11 , KC_F12 , KC_DEL ,
  60. _______ , _______ , SLC_ALL , SLC_ROW , SLC_WRD , _______, KC_BSPC, KC_HOME, KC_UP , KC_END , KC_BRIU, KC_BRID , KC_PSCR,
  61. _______ , _______ , LSFT(KC_DEL), LCTL(KC_INS), LSFT(KC_INS), KC_DEL , KC_ENT , KC_LEFT, KC_DOWN, KC_RIGHT, BL_TOGG, BL_STEP , BL_BRTG, _______,
  62. _______ , _______ , KC_MUTE , KC_VOLD , KC_VOLU , ALT_TAB, _______, _______, _______, _______ , _______, RESET , _______ ,
  63. _______ , _______ , _______ , _______, _______ , _______, _______
  64. )
  65. };
  66. // Set the unicode input mode for using UC.
  67. void matrix_init_user(void) {
  68. set_unicode_input_mode(UC_LNX);
  69. }
  70. // Processing all the key pressed.
  71. // Alt+tab.
  72. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  73. // Depending keycodes…
  74. switch (keycode) { // This will do most of the grunt work with the keycodes.
  75. case ALT_TAB:
  76. if (record->event.pressed) {
  77. if (!is_alt_tab_active) {
  78. is_alt_tab_active = true;
  79. register_code(KC_LALT);
  80. }
  81. alt_tab_timer = timer_read();
  82. register_code(KC_TAB);
  83. } else {
  84. unregister_code(KC_TAB);
  85. }
  86. break;
  87. case SLC_ALL:
  88. select_all(record);
  89. break;
  90. case SLC_ROW:
  91. select_row(record);
  92. break;
  93. case SLC_WRD:
  94. select_word(record);
  95. break;
  96. }
  97. return true;
  98. }
  99. void matrix_scan_user(void) { // The very important timer.
  100. if (is_alt_tab_active) {
  101. if (timer_elapsed(alt_tab_timer) > 750) {
  102. unregister_code(KC_LALT);
  103. is_alt_tab_active = false;
  104. }
  105. }
  106. }