Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/z6lm89/help_with_layer_switching_stack_overflow_the_key/
- * Code to create a button that will cycle through the layers, looping around to the beginning.
- * This can go into keymap.c
- */
- enum layer_names {
- _LAYER0,
- _LAYER1,
- _LAYER2,
- NUM_LAYERS, // Leave this at the end of the list
- };
- enum custom_keycodes {
- CYCLE_LAYERS = SAFE_RANGE, // Rename CYCLE_LAYERS to whatever you want, but leave SAFE_RANGE
- // Other macros...
- };
- /* This function is called automatically any time there is a layer change. */
- layer_state_t layer_state_set_user(layer_state_t state) {
- switch(get_highest_layer(state) {
- case _LAYER0: // If _LAYER0 is the highest active layer
- rgblight_setrgb(RGB_RED); // Set RGB to RED
- break;
- case _LAYER1: // If _LAYER1 is the highest active layer
- rgblight_setrgb(RGB_BLUE); // Set RGB to BLUE
- break;
- case _LAYER2: // If _LAYER2 is the highest active layer
- rgblight_setrgb(RGB_GREEN); // Set RGB to GREEN
- break;
- default:
- // instructions for any other layer
- break;
- }
- return true;
- }
- bool process_record_user(uint16_t keycode, keyrecord_t *record) {
- switch (keycode) {
- case CYCLE_LAYERS:
- if (record->event.pressed) {
- // Go to the next layer up, looping around to the beginning when the end is reached
- uint8_t next_layer = (get_highest_layer(layer_state) + 1) % NUM_LAYERS;
- layer_move(next_layer); // layer_move(layer) is the same as the TO(layer) keycode
- break;
- }
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement