1 /* Copyright 2017 Jeremy Cowgar
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 2 of the License, or
6 * (at your option) any later version.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #ifdef AUTO_SHIFT_ENABLE
21 #include "process_auto_shift.h"
27 #define TAP_WITH_MOD(mod, key) \
30 unregister_code(key); \
33 uint16_t autoshift_time = 0;
34 uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
35 uint16_t autoshift_lastkey = KC_NO;
37 bool autoshift_enabled = true;
39 void autoshift_timer_report(void) {
42 snprintf(display, 8, "\n%d\n", autoshift_timeout);
44 send_string((const char *)display);
47 void autoshift_on(uint16_t keycode) {
48 autoshift_time = timer_read();
49 autoshift_lastkey = keycode;
52 void autoshift_flush(void) {
53 if (autoshift_lastkey != KC_NO) {
54 uint16_t elapsed = timer_elapsed(autoshift_time);
56 if (elapsed > autoshift_timeout) {
57 register_code(KC_LSFT);
60 register_code(autoshift_lastkey);
61 unregister_code(autoshift_lastkey);
63 if (elapsed > autoshift_timeout) {
64 unregister_code(KC_LSFT);
68 autoshift_lastkey = KC_NO;
72 bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
73 static uint8_t any_mod_pressed;
75 if (record->event.pressed) {
78 autoshift_timeout += 5;
82 autoshift_timeout -= 5;
86 autoshift_timer_report();
90 if (autoshift_enabled) {
91 autoshift_enabled = false;
95 autoshift_enabled = true;
98 #ifndef NO_AUTO_SHIFT_ALPHA
126 #ifndef NO_AUTO_SHIFT_NUMERIC
138 #ifndef NO_AUTO_SHIFT_SPECIAL
151 if (!autoshift_enabled) return true;
155 any_mod_pressed = get_mods() & (
156 MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
157 MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
158 MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
159 MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
162 if (any_mod_pressed) {
166 autoshift_on(keycode);