Created
March 24, 2021 21:15
-
-
Save edwinclement08/38f1025b3b74b3320dfaef058d1fd8dc to your computer and use it in GitHub Desktop.
Switch programs in Mac with one key tap.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include QMK_KEYBOARD_H | |
#ifndef KEYMAP_PRE_CUSTOM | |
#define KEYMAP_PRE_CUSTOM | |
uint16_t cmd_tab_timer = 16960; | |
uint16_t cmd_tab_wait_delay = 700; | |
bool in_state = false; | |
enum custom_keycodes { | |
SWITCH_APPS = SAFE_RANGE, | |
}; | |
void switch_apps(void) { | |
register_code(KC_LGUI); | |
tap_code(KC_TAB); | |
register_code(KC_LALT); | |
unregister_code(KC_LGUI); | |
unregister_code(KC_LALT); | |
} | |
bool process_record_user(uint16_t keycode, keyrecord_t *record) { | |
switch (keycode) { | |
case SWITCH_APPS: | |
if (record->event.pressed) { | |
if (in_state ) { | |
cmd_tab_wait_delay = 400; | |
tap_code(KC_TAB); | |
} else { | |
in_state = true; | |
cmd_tab_wait_delay = 900; | |
register_code(KC_LGUI); | |
tap_code(KC_TAB); | |
} | |
cmd_tab_timer = timer_read(); | |
} | |
break; | |
} | |
return true; | |
} | |
void matrix_scan_user(void) { | |
if ( in_state && timer_read() - cmd_tab_timer > cmd_tab_wait_delay) { | |
in_state = false; | |
register_code(KC_LALT); | |
unregister_code(KC_LGUI); | |
unregister_code(KC_LALT); | |
} | |
} | |
#endif |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment