Skip to content

Instantly share code, notes, and snippets.

@derekmc
Last active September 28, 2025 16:21
Show Gist options
  • Select an option

  • Save derekmc/f1b9baf23339065beda636f45e6ebedf to your computer and use it in GitHub Desktop.

Select an option

Save derekmc/f1b9baf23339065beda636f45e6ebedf to your computer and use it in GitHub Desktop.
#include QMK_KEYBOARD_H
enum keycodes{
KC_CYCLE_LAYERS = QK_USER,
};
#define LAYER_CYCLE_START 0
#define LAYER_CYCLE_END 4
// Add the behaviour of this new keycode
bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case KC_CYCLE_LAYERS:
// Our logic will happen on presses, nothing is done on releases
if (!record->event.pressed) {
// We've already handled the keycode (doing nothing), let QMK know so no further code is run unnecessarily
return false;
}
uint8_t current_layer = get_highest_layer(layer_state);
// Check if we are within the range, if not quit
if (current_layer > LAYER_CYCLE_END || current_layer < LAYER_CYCLE_START) {
return false;
}
uint8_t next_layer = current_layer - current_layer%2 + 2;
if (next_layer >= LAYER_CYCLE_END) {
next_layer = LAYER_CYCLE_START;
}
layer_move(next_layer);
return false;
// Process other keycodes normally
default:
return true;
}
}
// Place `KC_CYCLE_LAYERS` as a keycode in your keymap
// clang-format off
const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
[0] = LAYOUT( /* Base */
KC_CAPS, KC_1, KC_2, KC_3, KC_4, KC_5, KC_6, KC_7, KC_8, KC_9, KC_0, KC_MINS, KC_EQL, KC_BSPC,
KC_TAB, KC_Q, KC_W, KC_E, KC_R, KC_T, KC_Y, KC_U, KC_I, KC_O, KC_P, KC_LBRC, KC_RBRC, KC_BSLS,
KC_ESC, KC_A, KC_S, KC_D, KC_F, KC_G, KC_H, KC_J, KC_K, KC_L, KC_SCLN, KC_QUOT, KC_BSLS, KC_ENT ,
KC_LSFT, KC_NUBS, KC_Z, KC_X, KC_C, KC_V, KC_B, KC_N, KC_M, KC_COMM, KC_DOT, KC_SLSH, KC_INT1, KC_RSFT,
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(1), KC_APP, KC_RCTL
),
[1] = LAYOUT( /* Base */
KC_CYCLE_LAYERS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,
_______, _______, KC_UP, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_HOME, KC_END, _______,
KC_GRV, KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, _______, _______, _______, KC_SCRL, KC_PGUP, KC_PGDN, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, KC_SCRL, KC_INS, KC_DEL, _______, _______,
_______, GU_TOGG, _______, _______, _______, _______, KC_APP, _______
),
[2] = LAYOUT( /* Zilted Graphite */
KC_CAPS, KC_B, KC_Q, KC_L, KC_D, KC_4, KC_5, KC_6, KC_O, KC_U, KC_SCLN, KC_J, KC_7, KC_BSPC,
KC_TAB, KC_N, KC_R, KC_T, KC_W, KC_Z, KC_QUOT, KC_F, KC_A, KC_E, KC_I, KC_COMM, KC_EQL, KC_BSLS,
KC_ESC, KC_1, KC_X, KC_M, KC_S, KC_G, KC_Y, KC_H, KC_DOT, KC_MINS, KC_SLSH, KC_8, KC_BSLS, KC_ENT ,
KC_LSFT, KC_NUBS, KC_2, KC_3, KC_C, KC_V, KC_0, KC_K, KC_P, KC_LBRC, KC_RBRC, KC_9, KC_INT1, KC_RSFT,
KC_LCTL, KC_LGUI, KC_LALT, KC_SPC, KC_RALT, MO(3), KC_APP, KC_RCTL
),
[3] = LAYOUT(
KC_CYCLE_LAYERS, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______,
_______, _______, KC_UP, _______, _______, _______, _______, _______, _______, _______, KC_PSCR, KC_HOME, KC_END, _______,
KC_GRV, KC_LEFT, KC_DOWN, KC_RIGHT, _______, _______, KC_Q, _______, _______, KC_SCRL, KC_PGUP, KC_PGDN, _______, _______,
_______, _______, _______, _______, _______, _______, _______, _______, _______, KC_SCRL, KC_INS, KC_DEL, _______, _______,
_______, GU_TOGG, _______, _______, _______, _______, KC_APP, _______
),
};
// clang-format on
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment