summaryrefslogtreecommitdiffstats
path: root/quantum/process_keycode
diff options
context:
space:
mode:
authorJeremy Cowgar <jeremy@cowgar.com>2017-09-17 01:33:28 -0400
committerJack Humbert <jack.humb@gmail.com>2017-09-18 17:08:18 -0400
commitabba393f57fdfb9b7abd92cc7925a605619902b2 (patch)
tree83db1c4e0aaaca008a49312b9d2d9197d1837f7b /quantum/process_keycode
parent87021371e6273258a9385a0a5ed4cfd344f9de8f (diff)
Added Auto Shift, tap key = normal, hold key = shifted state.
Diffstat (limited to 'quantum/process_keycode')
-rw-r--r--quantum/process_keycode/process_auto_shift.c168
-rw-r--r--quantum/process_keycode/process_auto_shift.h28
2 files changed, 196 insertions, 0 deletions
diff --git a/quantum/process_keycode/process_auto_shift.c b/quantum/process_keycode/process_auto_shift.c
new file mode 100644
index 0000000000..55b5244501
--- /dev/null
+++ b/quantum/process_keycode/process_auto_shift.c
@@ -0,0 +1,168 @@
+/* Copyright 2017 Jeremy Cowgar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifdef AUTO_SHIFT_ENABLE
+
+#include <stdio.h>
+
+#include "process_auto_shift.h"
+
+#define TAP(key) \
+ register_code(key); \
+ unregister_code(key)
+
+#define TAP_WITH_MOD(mod, key) \
+ register_code(mod); \
+ register_code(key); \
+ unregister_code(key); \
+ unregister_code(mod)
+
+uint16_t autoshift_time = 0;
+uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
+uint16_t autoshift_lastkey = KC_NO;
+
+void autoshift_timer_report(void) {
+ char display[8];
+
+ snprintf(display, 8, "\n%d\n", autoshift_timeout);
+
+ send_string((const char *)display);
+}
+
+void autoshift_on(uint16_t keycode) {
+ autoshift_time = timer_read();
+ autoshift_lastkey = keycode;
+}
+
+void autoshift_flush(void) {
+ if (autoshift_lastkey != KC_NO) {
+ uint16_t elapsed = timer_elapsed(autoshift_time);
+
+ if (elapsed > autoshift_timeout) {
+ register_code(KC_LSFT);
+ }
+
+ register_code(autoshift_lastkey);
+ unregister_code(autoshift_lastkey);
+
+ if (elapsed > autoshift_timeout) {
+ unregister_code(KC_LSFT);
+ }
+
+ autoshift_time = 0;
+ autoshift_lastkey = KC_NO;
+ }
+}
+
+bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
+ static uint8_t any_mod_pressed;
+
+ if (record->event.pressed) {
+ switch (keycode) {
+ case KC_ASUP:
+ autoshift_timeout += 5;
+ return false;
+
+ case KC_ASDN:
+ autoshift_timeout -= 5;
+ return false;
+
+ case KC_ASRP:
+ autoshift_timer_report();
+ return false;
+
+#ifndef NO_AUTO_SHIFT_ALPHA
+ case KC_A:
+ case KC_B:
+ case KC_C:
+ case KC_D:
+ case KC_E:
+ case KC_F:
+ case KC_G:
+ case KC_H:
+ case KC_I:
+ case KC_J:
+ case KC_K:
+ case KC_L:
+ case KC_M:
+ case KC_N:
+ case KC_O:
+ case KC_P:
+ case KC_Q:
+ case KC_R:
+ case KC_S:
+ case KC_T:
+ case KC_U:
+ case KC_V:
+ case KC_W:
+ case KC_X:
+ case KC_Y:
+ case KC_Z:
+#endif
+#ifndef NO_AUTO_SHIFT_NUMERIC
+ case KC_1:
+ case KC_2:
+ case KC_3:
+ case KC_4:
+ case KC_5:
+ case KC_6:
+ case KC_7:
+ case KC_8:
+ case KC_9:
+ case KC_0:
+#endif
+#ifndef NO_AUTO_SHIFT_SPECIAL
+ case KC_TILD:
+ case KC_MINUS:
+ case KC_EQL:
+ case KC_TAB:
+ case KC_LBRC:
+ case KC_RBRC:
+ case KC_BSLS:
+ case KC_SCLN:
+ case KC_QUOT:
+ case KC_COMM:
+ case KC_DOT:
+ case KC_SLSH:
+#endif
+ autoshift_flush();
+
+ any_mod_pressed = get_mods() & (
+ MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
+ MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
+ MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
+ MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
+ );
+
+ if (any_mod_pressed) {
+ return true;
+ }
+
+ autoshift_on(keycode);
+ return false;
+
+ default:
+ autoshift_flush();
+ return true;
+ }
+ } else {
+ autoshift_flush();
+ }
+
+ return true;
+}
+
+#endif
diff --git a/quantum/process_keycode/process_auto_shift.h b/quantum/process_keycode/process_auto_shift.h
new file mode 100644
index 0000000000..a0361346bd
--- /dev/null
+++ b/quantum/process_keycode/process_auto_shift.h
@@ -0,0 +1,28 @@
+/* Copyright 2017 Jeremy Cowgar
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef PROCESS_AUTO_SHIFT_H
+#define PROCESS_AUTO_SHIFT_H
+
+#include "quantum.h"
+
+#ifndef AUTO_SHIFT_TIMEOUT
+ #define AUTO_SHIFT_TIMEOUT 175
+#endif
+
+bool process_auto_shift(uint16_t keycode, keyrecord_t *record);
+
+#endif