keymap.c 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. QK_BOOT, KC_ACL0, KC_ACL1,
  30. KC_VOLU, KC_ACL2, KC_BRIU,
  31. KC_VOLD, TO(1), KC_BRID
  32. ),
  33. };
  34. bool 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. return true;
  50. }
  51. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  52. switch (keycode) { // This will do most of the grunt work with the keycodes.
  53. case ALT_TAB:
  54. if (record->event.pressed) {
  55. if (!is_alt_tab_active) {
  56. is_alt_tab_active = true;
  57. register_code(KC_LALT);
  58. }
  59. alt_tab_timer = timer_read();
  60. register_code(KC_TAB);
  61. } else {
  62. unregister_code(KC_TAB);
  63. }
  64. break;
  65. }
  66. return true;
  67. }
  68. void matrix_scan_user(void) { // The very important timer.
  69. if (is_alt_tab_active) {
  70. if (timer_elapsed(alt_tab_timer) > 1000) {
  71. unregister_code(KC_LALT);
  72. is_alt_tab_active = false;
  73. }
  74. }
  75. }