Skip to content

Commit

Permalink
Shift+Backspace to Delete
Browse files Browse the repository at this point in the history
  • Loading branch information
tacahiroy committed Jan 10, 2024
1 parent d532b92 commit b29f163
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 7 deletions.
8 changes: 4 additions & 4 deletions keyboards/hineybush/h60/keymaps/tacahiroy/keymap.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ const uint16_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
),

[_LOWER] = LAYOUT_60_tsangan_hhkb(
W_IME, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, KC_MUTE, KC_MPLY,
_______, _______, XX_TAB, _______, _______, _______, TM_SLST, TM_PREV, TM_WLST, TM_NEXT, KC_PIPE, KC_VOLD, KC_VOLU, KC_DEL,
_______, _______, MOUS, W_SNIP, KC_F5, KC_F3, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, TM_SSH, _______, _______,
_______, _______, CUT, COPY2, PASTE2, TOP, BOTTOM, KC_HOME, KC_END, _______, TM_LASS, _______, _______,
W_IME, KC_F1, KC_F2, KC_F3, KC_F4, KC_F5, KC_F6, KC_F7, KC_F8, KC_F9, KC_F10, KC_F11, KC_F12, _______, _______,
_______, _______, XX_TAB, _______, _______, _______, TM_SLST, TM_PREV, TM_WLST, TM_NEXT, KC_PIPE, KC_VOLD, KC_VOLU, KC_MPLY,
_______, _______, MOUS, W_SNIP, KC_F5, KC_F3, KC_LEFT, KC_DOWN, KC_UP, KC_RGHT, TM_SSH, TM_LASS, _______,
_______, _______, CUT, COPY2, PASTE2, TOP, BOTTOM, KC_HOME, KC_END, _______, _______, _______, _______,
_______, _______, _______, JP_HENK, _______, _______, _______
),

Expand Down
46 changes: 43 additions & 3 deletions users/tacahiroy/tacahiroy.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@
*/
#include "tacahiroy.h"

// Initialize variable holding the binary
// representation of active modifiers.
uint8_t mod_state;

static bool lower_pressed = false;
static bool raise_pressed = false;

void toggle_ime(bool is_on) {
if (is_on) {
Expand All @@ -26,9 +32,6 @@ void toggle_ime(bool is_on) {
}
}

static bool lower_pressed = false;
static bool raise_pressed = false;

bool process_record_user(uint16_t keycode, keyrecord_t *record) {
switch (keycode) {
case COLEMAK:
Expand Down Expand Up @@ -123,6 +126,12 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
return false;

// https://docs.qmk.fm/#/feature_advanced_keycodes?id=shift-backspace-for-delete
case KC_BSPC:
// Store the current modifier state in the variable for later reference
mod_state = get_mods();
return shift_backspace_for_delete(record);

default:
if (record->event.pressed) {
lower_pressed = false;
Expand All @@ -132,3 +141,34 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) {
}
return true;
}

bool shift_backspace_for_delete(keyrecord_t *record) {
// Initialize a boolean variable that keeps track
// of the delete key status: registered or not?
static bool delkey_registered;
if (record->event.pressed) {
// Detect the activation of either shift keys
if (mod_state & MOD_MASK_SHIFT) {
// First temporarily canceling both shifts so that
// shift isn't applied to the KC_DEL keycode
del_mods(MOD_MASK_SHIFT);
register_code(KC_DEL);
// Update the boolean variable to reflect the status of KC_DEL
delkey_registered = true;
// Reapplying modifier state so that the held shift key(s)
// still work even after having tapped the Backspace/Delete key.
set_mods(mod_state);
return false;
}
} else { // on release of KC_BSPC
// In case KC_DEL is still being sent even after the release of KC_BSPC
if (delkey_registered) {
unregister_code(KC_DEL);
delkey_registered = false;
return false;
}
}

// Let QMK process the KC_BSPC keycode as usual outside of shift
return true;
}
1 change: 1 addition & 0 deletions users/tacahiroy/tacahiroy.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ enum tacahiroy_keycodes {
};

void toggle_ime(bool is_on);
bool shift_backspace_for_delete(keyrecord_t *record);

#define LOWER LT(_LOWER, JP_MHEN)
#define RAISE LT(_RAISE, JP_HENK)
Expand Down

0 comments on commit b29f163

Please sign in to comment.