#include QMK_KEYBOARD_H #include "keycodes.h" bool keycodes_process_record(uint16_t keycode, keyrecord_t *record) { static bool kc_lgui = false; static bool kc_ralt = false; switch (keycode) { case KC_ESC: /* By default, send the ESC code to the host. * This code will be muted if there is a specific state to remove firts. * The keys L_GUI and R_ALT activate a layer automatically, but can be * used in a combo with the ESC key, I do not want to ignore the key press * in this case. */ bool handle_key = true; if (get_oneshot_mods()) { clear_oneshot_mods(); handle_key = false; } if ( (! kc_ralt) \ && (! kc_lgui) \ && (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) )) { // Remove the layer the key is released. layer_clear(); handle_key = false; } if (host_keyboard_led_state().caps_lock) { tap_code16(KC_CAPS_LOCK); handle_key = false; } return handle_key; case AL_ENT: if (!record->event.pressed \ && (! kc_lgui) \ && (layer_state_is(LAYER_KEYPAD) || layer_state_is(LAYER_ARROW) )) { // Remove the layer the key is released. layer_clear(); } return true; // Override the key APP when hold into AltGR + Layer 1 when hold case KEY_APP: if (!record->tap.count && record->event.pressed) { kc_ralt = record->event.pressed; register_code(KC_RIGHT_ALT); layer_on(LAYER_ARROW); return false; } else if (!record->tap.count && !record->event.pressed) { kc_ralt = record->event.pressed; unregister_code(KC_RIGHT_ALT); layer_off(LAYER_ARROW); return false; } return true; case KC_LGUI: kc_lgui = record->event.pressed; if (record->event.pressed) { layer_on(LAYER_ARROW); } else { layer_off(LAYER_ARROW); } return true; default: return true; // Process all other keycodes normally } }