Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/plqic8/ctrla_macro_sends_a_7_instead/
- * Code to include a macro key that is normally alt, but sends CTRL+A on tap.
- * This goes into keymap.c
- *
- * If you press another key while LDR_ALT is held down, this code assumes you're using ALT like normal
- * Otherwise, it will tap CTRL+A if you've held LDR_ALT for less than TAPPING_TERM.
- * This defaults to 200ms, and can be changed by defining it in config.h with #define TAPPING_TERM 150
- */
- #define LEADER LCTL(KC_A) //CTRL+A, your leader shortcut
- enum custom_keycodes {
- LDR_ALT = SAFE_RANGE, //normally alt, Ctrl+A on tap
- //other macros,
- };
- bool key_pressed = false; //variable used to check if a key is pressed while LDR_ALT is held
- uint16_t LDR_ALT_timer = 0; //declare a timer variable to track hold time for LDR_ALT
- bool process_record_user(uint16_t keycode, keyrecord_t *record) {
- if (record->event.pressed)
- key_pressed = true; //if any key is pressed, set key_pressed to true
- switch (keycode) {
- case LDR_ALT:
- if (record->event.pressed) { //when LDR_ALT is pressed
- register_code(KC_RALT); // press right alt
- key_pressed = false; // set key_pressed to false
- LDR_ALT_timer = timer_read(); // mark the time LDR_ALT was pressed
- } else { //when LDR_ALT is released
- unregister_code(KC_RALT); // release right alt
- if (key_pressed) break; // if another key was pressed while alt was held, exit and do not tap leader shortcut
- if (timer_elapsed(LDR_ALT_timer) < TAPPING_TERM) { //if LDR_ALT was held for less than TAPPING_TERM (default 200ms)
- tap_code16(LEADER); // tap the LEADER shortcut, LCTL(KC_A) CTRL+A
- }
- }
- break;
- }
- return true;
- };
Add Comment
Please, Sign In to add comment