summaryrefslogtreecommitdiffstats
path: root/users/ericgebhart/extensions/alt_shift.c
diff options
context:
space:
mode:
Diffstat (limited to 'users/ericgebhart/extensions/alt_shift.c')
-rw-r--r--users/ericgebhart/extensions/alt_shift.c99
1 files changed, 99 insertions, 0 deletions
diff --git a/users/ericgebhart/extensions/alt_shift.c b/users/ericgebhart/extensions/alt_shift.c
new file mode 100644
index 0000000000..002adec230
--- /dev/null
+++ b/users/ericgebhart/extensions/alt_shift.c
@@ -0,0 +1,99 @@
+#include USERSPACE_H
+#include <stdbool.h>
+#include <stdint.h>
+
+bool shift_for_two(uint16_t keycode, keyrecord_t *record){
+ uint16_t mod_state = get_mods();
+
+ bool is_shifted = (get_mods() & MOD_MASK_SHIFT) ||
+ (get_oneshot_mods() & MOD_MASK_SHIFT);
+
+ if(record ->event.pressed) {
+ // If shifted, double these common punctuation marks.
+ if(is_shifted){
+ // clear shift temporarily
+ del_mods(MOD_MASK_SHIFT);
+ del_oneshot_mods(MOD_MASK_SHIFT);
+
+ tap_code16(keycode);
+ tap_code16(keycode);
+
+ // restore previous shift state
+ set_mods(mod_state);
+ return false;
+ }
+ }
+ return true;
+}
+
+bool shift_for_three(uint16_t keycode, keyrecord_t *record){
+ uint16_t mod_state = get_mods();
+
+ bool is_shifted = (get_mods() & MOD_MASK_SHIFT) ||
+ (get_oneshot_mods() & MOD_MASK_SHIFT);
+
+ if(record ->event.pressed) {
+ // If shifted, double these common punctuation marks.
+ if(is_shifted){
+ // clear shift temporarily
+ del_mods(MOD_MASK_SHIFT);
+ del_oneshot_mods(MOD_MASK_SHIFT);
+
+ tap_code16(keycode);
+ tap_code16(keycode);
+ tap_code16(keycode);
+
+ // restore previous shift state
+ set_mods(mod_state);
+ return false;
+ }
+ }
+ return true;
+ }
+
+bool override_shift(uint16_t keycode,
+ uint16_t shift_keycode,
+ keyrecord_t *record
+ ) {
+
+ bool is_shifted = (get_mods() & MOD_MASK_SHIFT) ||
+ (get_oneshot_mods() & MOD_MASK_SHIFT);
+
+ if (record->event.pressed) {
+ if (is_shifted) {
+ uint8_t mod_state = get_mods();
+ del_mods(MOD_MASK_SHIFT);
+ del_oneshot_mods(MOD_MASK_SHIFT);
+
+ tap_code16(shift_keycode);
+
+ set_mods(mod_state);
+ } else {
+ //tap_code16(keycode);
+ }
+ }
+ return false;
+}
+
+// macros for use in alt_shift.defs.
+#define ALT_SHIFT(KCKEY, KC01) \
+ case KCKEY: \
+ return override_shift(KCKEY, KC01, record); \
+ break;
+
+#define SHIFT_FOR_2(KCKEY) \
+ case KCKEY: \
+ return shift_for_two(KCKEY, record); \
+ break;
+
+#define SHIFT_FOR_3(KCKEY) \
+ case KCKEY: \
+ return shift_for_three(KCKEY, record); \
+ break;
+
+bool process_alt_shift_user(uint16_t keycode, keyrecord_t *record) {
+ switch(keycode){
+#include "alt_shift.def"
+ }
+ return true;
+}