Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* https://www.reddit.com/r/olkb/comments/plk4ts/shift_tap_one_shot/
- * Code to include a macro key that is normally shift, but activates a oneshot layer on tap.
- * This goes into keymap.c
- *
- * The macro name used here is SH_LAY2, for SHIFT_LAYER2. Call it what you want, but update everywhere it is mentioned.
- * It will press(register_code) and release(unregister_code) KC_LSFT, left shift. Change this key on lines 31 and 35.
- * Update the oneshot layer on line 39.
- * SH_LAY2_timer is specific to SH_LAY2. Rename it if you rename SH_LAY2 to avoid confusion, and create another timer for each key like this.
- *
- * If you press another key while SH_LAY2 is held down, this code assumes you're using shift like normal, and will not activate the oneshot layer.
- * Otherwise, the oneshot will activate if you've held SH_LAY2 for less than TAPPING_TERM.
- * This defaults to 200ms, and can be changed by defining it in config.h #define TAPPING_TERM 150
- */
- enum custom_keycodes {
- SH_LAY2 = SAFE_RANGE, //normal shift, oneshot layer 2 on tap
- //other macros,
- };
- bool key_pressed = false; //variable used to check if a key is pressed while SH_LAY2 is held
- uint16_t SH_LAY2_timer = 0; //declare a timer variable to track hold time for SH_LAY2
- 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 SH_LAY2:
- if (record->event.pressed) { //when SH_LAY2 is pressed
- register_code(KC_LSFT); // press left shift
- key_pressed = false; // set key_pressed to false
- SH_LAY2_timer = timer_read(); // mark the time SH_LAY2 was pressed
- } else { //when SH_LAY2 is released
- unregister_code(KC_LSFT); // release left shift
- if (key_pressed) break; // if another key was pressed while shift was held, exit and do not use one shot layer
- if (timer_elapsed(SH_LAY2_timer) < TAPPING_TERM) { //if SH_LAY2 was held for less than TAPPING_TERM (default 200ms)
- set_oneshot_layer( 2 , ONESHOT_START); // activate oneshot layer 2 (replace '2' with layer name or #)
- clear_oneshot_layer_state(ONESHOT_PRESSED); // necessary for oneshots in macros. don't touch this line
- }
- }
- break;
- }
- return true;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement