From b687e34fe4712db8adf5e9843ad0a490d2c509ae Mon Sep 17 00:00:00 2001 From: Ashelyn Rose Date: Fri, 16 Apr 2021 22:28:58 -0600 Subject: [PATCH] Vim key nav --- keymap/keymap.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++- keymap/keymap.h | 4 ++++ 2 files changed, 64 insertions(+), 1 deletion(-) diff --git a/keymap/keymap.c b/keymap/keymap.c index 4362196..507bbe6 100644 --- a/keymap/keymap.c +++ b/keymap/keymap.c @@ -247,8 +247,67 @@ bool process_record_user(uint16_t keycode, keyrecord_t *record) { return false; } default: - return true; //Process all other keycodes normally + break; //Process all other keycodes normally } + + if (keycode == KC_LGUI) { + if (record->event.pressed && !gui_key_down) { + gui_key_down = true; + } else if (!record->event.pressed && gui_key_down) { + if (gui_combo_pressed) { + unregister_code(KC_LGUI); + } else if (!gui_disable_tap) { + tap_code(KC_LGUI); + } + + gui_key_down = false; + gui_combo_pressed = false; + gui_disable_tap = false; + } + return false; + } + + if (!gui_key_down){ + return true; + } + + // Vim keys + if(!gui_combo_pressed) { + uint16_t target = 0; + + if(keycode == KC_H){ + target = KC_LEFT; + } + + if(keycode == KC_J){ + target = KC_DOWN; + } + + if(keycode == KC_K){ + target = KC_UP; + } + + if(keycode == KC_L){ + target = KC_RIGHT; + } + + if (target != 0) { + if(record->event.pressed) { + register_code(target); + gui_disable_tap = true; + } else { + unregister_code(target); + } + return false; + } + } + + if(!gui_combo_pressed) { + gui_combo_pressed = true; + register_code(KC_LGUI); + } + + return true; } void set_layer_color(int layer) { diff --git a/keymap/keymap.h b/keymap/keymap.h index d3b8192..5a96902 100644 --- a/keymap/keymap.h +++ b/keymap/keymap.h @@ -29,3 +29,7 @@ enum layout_names { extern bool g_suspend_state; extern rgb_config_t rgb_matrix_config; bool disable_layer_color; + +bool gui_key_down; +bool gui_combo_pressed; +bool gui_disable_tap; \ No newline at end of file