Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/qfkzan/quick_qmk_question/
- * Code to include a macro key that is normally ALT, but sends ALT+TAB on tap.
- * This goes into keymap.c
- *
- * If you press another key while ALT_TAB is held down, this code assumes you're using ALT like normal
- * Otherwise, it will tap ALT+TAB if you've held ALT_TAB for less than TAPPING_TERM.
- * This defaults to 200ms, and can be changed by defining it in config.h with #define TAPPING_TERM 150
- */
- enum custom_keycodes {
- ALT_TAB = SAFE_RANGE, //the custom macro key that you'll place into your keymap
- //other macros,
- };
- static uint16_t ALT_TAB_timer = 0; //declare a timer variable to track hold time for ALT_TAB
- static bool key_pressed = false; //variable used to check if a key was pressed while ALT_TAB was held
- bool process_record_user(uint16_t keycode, keyrecord_t *record) {
- if (record->event.pressed)
- key_pressed = true; //if any key is pressed, set key_pressed to true
- switch(keycode) {
- case ALT_TAB:
- if (record->event.pressed) { //when ALT_TAB is pressed
- register_code(KC_LALT); // press left alt
- ALT_TAB_timer = timer_read(); // mark the time ALT_TAB is pressed
- key_pressed = false; // set key_pressed to false
- } else { //when ALT_TAB is released
- unregister_code(KC_LALT); // release left alt
- if (key_pressed) //if another key was pressed while ALT_TAB was held,
- return false; // do nothing else
- if (timer_elapsed(ALT_TAB_timer) < TAPPING_TERM) { //if ALT_TAB was held for less than TAPPING_TERM
- tap_code16( LALT(KC_TAB) ); // tap ALT+TAB
- }
- }
- break;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement