Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/12wg84s/is_there_a_way_to_determine_if_a_key_is_bound_or/
- * QMK code to set the color of the LEDs on keys that have a keycode assigned to them, on certain layers.
- * Replace _MODLAYER1 and _MODLAYER2 with the names or numbers of your desired layers.
- * Replace RGB_GREEN and RGB_MAGENTA with the desired color for each layer.
- * This can be a named color from https://github.com/qmk/qmk_firmware/blob/master/quantum/color.h
- * or 3 separate values for red, green, and blue. e.g. highlight_bound_keys(_MODLAYER1, 0, 255, 0);
- *
- * This can go into keymap.c
- */
- void highlight_bound_keys(uint8_t layer, uint8_t red, uint8_t green, uint8_t blue) {
- for (uint8_t row = 0; row < MATRIX_ROWS; row++) {
- for (uint8_t col = 0; col < MATRIX_COLS; col++) {
- uint8_t led_index;
- // Returns false if there is no LED at this key position
- // Otherwise, it writes the index of the LED to the given variable
- if (!rgb_matrix_map_row_column_to_led(row, col, &led_index))
- continue; // Skip any key with no led
- // If the current key has a keycode assigned to it, set the LED to the given color
- // If the key is KC_NO or KC_TRANSPARENT, set the LED color to black/off
- if (keycode_at_keymap_location(layer, row, col) > KC_TRANSPARENT) {
- rgb_matrix_set_color(led_index, red, green, blue);
- } else {
- rgb_matrix_set_color(led_index, RGB_OFF);
- }
- }
- }
- }
- bool rgb_matrix_indicators_advanced_user(uint8_t led_min, uint8_t led_max) {
- switch(get_highest_layer(layer_state)) {
- case _MODLAYER1: // if _MODLAYER1 is the top active layer
- highlight_bound_keys(_MODLAYER1, RGB_GREEN); // highlight keys that have keycodes with the color GREEN
- break;
- case _MODLAYER2: // if _MODLAYER2 is the top active layer
- highlight_bound_keys(_MODLAYER2, RGB_MAGENTA); // highlight keys that have keycodes with the color MAGENTA
- break;
- }
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement