super-alt-tab.c 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Cool Function where a single key does ALT+TAB
  3. * From: https://beta.docs.qmk.fm/features/feature_macros#super-alt-tab
  4. */
  5. bool is_alt_tab_active = false; // ADD this near the begining of keymap.c
  6. uint16_t alt_tab_timer = 0; // we will be using them soon.
  7. enum custom_keycodes { // Make sure have the awesome keycode ready
  8. ALT_TAB = SAFE_RANGE,
  9. };
  10. // key processing
  11. bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  12. switch (keycode) { // This will do most of the grunt work with the keycodes.
  13. case ALT_TAB:
  14. if (record->event.pressed) {
  15. if (!is_alt_tab_active) {
  16. is_alt_tab_active = true;
  17. register_code(KC_LALT);
  18. }
  19. alt_tab_timer = timer_read();
  20. register_code(KC_TAB);
  21. } else {
  22. unregister_code(KC_TAB);
  23. }
  24. break;
  25. }
  26. return true;
  27. }
  28. // The very important timer.
  29. void matrix_scan_user(void) {
  30. if (is_alt_tab_active && timer_elapsed(alt_tab_timer) > 1000) {
  31. unregister_code(KC_LALT);
  32. is_alt_tab_active = false;
  33. }
  34. }