keymap.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. /* Copyright 2019 Danny Nguyen <danny@keeb.io>
  2. *
  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. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include QMK_KEYBOARD_H
  17. bool is_alt_tab_active = false; // ADD this near the begining of keymap.c
  18. uint16_t alt_tab_timer = 0; // we will be using them soon.
  19. enum custom_keycodes { // Make sure have the awesome keycode ready
  20. ALT_TAB = SAFE_RANGE,
  21. };
  22. const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
  23. [0] = LAYOUT(
  24. KC_MS_BTN1, KC_MS_BTN2, KC_MS_BTN3,
  25. KC_WH_U, ALT_TAB, KC_WH_L,
  26. KC_WH_D, TT(1), KC_WH_R
  27. ),
  28. [1] = LAYOUT(
  29. RESET, KC_ACL0, KC_ACL1,
  30. KC_VOLU, KC_ACL2, KC_BRIU,
  31. KC_VOLD, TO(1), KC_BRID
  32. ),
  33. };
  34. void encoder_update_user(uint8_t index, bool clockwise) {
  35. if (index == 0) {
  36. if (clockwise) {
  37. tap_code(KC_MS_LEFT);
  38. } else {
  39. tap_code(KC_MS_RIGHT);
  40. }
  41. }
  42. else if (index == 1) {
  43. if (clockwise) {
  44. tap_code(KC_MS_U);
  45. } else {
  46. tap_code(KC_MS_D);
  47. }
  48. }
  49. }
  50. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  51. switch (keycode) { // This will do most of the grunt work with the keycodes.
  52. case ALT_TAB:
  53. if (record->event.pressed) {
  54. if (!is_alt_tab_active) {
  55. is_alt_tab_active = true;
  56. register_code(KC_LALT);
  57. }
  58. alt_tab_timer = timer_read();
  59. register_code(KC_TAB);
  60. } else {
  61. unregister_code(KC_TAB);
  62. }
  63. break;
  64. }
  65. return true;
  66. }
  67. void matrix_scan_user(void) { // The very important timer.
  68. if (is_alt_tab_active) {
  69. if (timer_elapsed(alt_tab_timer) > 1000) {
  70. unregister_code(KC_LALT);
  71. is_alt_tab_active = false;
  72. }
  73. }
  74. }