Skip to content

Instantly share code, notes, and snippets.

@BundleOfJoysticks
Created February 15, 2019 03:40
Show Gist options
  • Save BundleOfJoysticks/5e1324eaebf6b82f2fb8b1eaf2224890 to your computer and use it in GitHub Desktop.
Save BundleOfJoysticks/5e1324eaebf6b82f2fb8b1eaf2224890 to your computer and use it in GitHub Desktop.
QMK Alt-Tab macro
#define ALT_TAB M(KC_ALT_TAB) // Macro for Alt-Tab
enum macro_keycodes {
KC_ALT_TAB
};
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT(
KC_MUTE, KC_ESC, KC_MPLY, \
MO(1), KC_UP, ALT_TAB, \
KC_LEFT, KC_DOWN, KC_RGHT \
),
[1] = LAYOUT(
RESET, BL_STEP, KC_STOP, \
_______, KC_PGUP, BL_STEP, \
KC_HOME, KC_PGDN, KC_END \
),
};
const macro_t *action_get_macro(keyrecord_t *record, uint8_t id, uint8_t opt) {
if (!eeconfig_is_enabled()) {
eeconfig_init();
}
switch (id) {
case KC_ALT_TAB:
return (record->event.pressed ? MACRO( D(LALT), D(TAB), END ) : MACRO( U(TAB), END ));
}
return MACRO_NONE;
}
@BundleOfJoysticks
Copy link
Author

@cgkades
Copy link

cgkades commented Feb 15, 2019

/* Copyright 2019 Danny Nguyen <danny@keeb.io>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
#include QMK_KEYBOARD_H
#define _NORM 0
#define _LOWER 3
#define _RAISE 4

#define LOWER  MO(_LOWER)
#define RAISE  MO(_RAISE)
#define ADJUST MO(_ADJUST)

enum custom_keycodes {
  KY_MSCODE = SAFE_RANGE,
  KY_VSTUDIO,
  KY_PYCHRM,
  KY_SPOTIFY,
  ALT_TAB
};

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
  switch (keycode) {
    case KY_MSCODE:
      if (record->event.pressed) {
        // when keycode QMKBEST is pressed
        SEND_STRING(SS_LGUI(SS_LALT(SS_LCTRL("v"))));
      } else {
        // when keycode QMKBEST is released
      }
      break;
    case KY_VSTUDIO:
      if (record->event.pressed) {
        // when keycode QMKBEST is pressed
        SEND_STRING(SS_LGUI(SS_LALT(SS_LCTRL("s"))));
      } else {
        // when keycode QMKBEST is released
      }
      break;
    case KY_PYCHRM:
      if (record->event.pressed) {
        // when keycode QMKBEST is pressed
        SEND_STRING(SS_LGUI(SS_LALT(SS_LCTRL("c"))));
      } else {
        // when keycode QMKBEST is released
      }
      break;
      case KY_SPOTIFY:
      if (record->event.pressed) {
        // when keycode QMKBEST is pressed
        SEND_STRING(SS_LGUI(SS_LALT(SS_LCTRL("p"))));
      } else {
        // when keycode QMKBEST is released
      }
      break;
      case ALT_TAB:
      if (record->event.pressed) {
        // when keycode QMKBEST is pressed
        SEND_STRING(SS_DOWN(X_LGUI));
        SEND_STRING(SS_TAP(X_TAB));
      } else {
        SEND_STRING(SS_UP(X_LGUI));
      }
      break;

  }
  return true;
};

const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    [_NORM] = LAYOUT(
        KC_A,    KY_SPOTIFY,    KC_C, \
        LOWER, KC__MUTE,   RAISE, \
        KC_MRWD, KC_MPLY, KC_MFFD \
    ),
    [_LOWER] = LAYOUT(
        KC_A,    KY_MSCODE,    KC_C, \
        _______, KY_PYCHRM,   _______, \
        KC_MRWD, ALT_TAB, KC_MFFD \
    ),
    [_RAISE] = LAYOUT(
        KC_A,    KY_VSTUDIO,    KC_C, \
        _______, KC__MUTE,   _______, \
        KC_MRWD, KC_MPLY, KC_MFFD \
    ),
};

void encoder_update_user(uint8_t index, bool clockwise) {
    if (index == 0) {
        if (clockwise) {
            tap_code(KC__VOLDOWN);
        } else {
            tap_code(KC__VOLUP);
        }
    }
    else if (index == 1) {
        if (clockwise) {
            tap_code(KC_BRID);
        } else {
            tap_code(KC_BRIU);
        }
    }
}

@PeterMortensen
Copy link

@PeterMortensen
Copy link

I think the macro keycode should be offset (not start at 0):

KC_ALT_TAB = SAFE_RANGE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment