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 void autoshift_timer_report(void) {
40 snprintf(display, 8, "\n%d\n", autoshift_timeout);
42 send_string((const char *)display);
45 void autoshift_on(uint16_t keycode) {
46 autoshift_time = timer_read();
47 autoshift_lastkey = keycode;
50 void autoshift_flush(void) {
51 if (autoshift_lastkey != KC_NO) {
52 uint16_t elapsed = timer_elapsed(autoshift_time);
54 if (elapsed > autoshift_timeout) {
55 register_code(KC_LSFT);
58 register_code(autoshift_lastkey);
59 unregister_code(autoshift_lastkey);
61 if (elapsed > autoshift_timeout) {
62 unregister_code(KC_LSFT);
66 autoshift_lastkey = KC_NO;
70 bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
71 static uint8_t any_mod_pressed;
73 if (record->event.pressed) {
76 autoshift_timeout += 5;
80 autoshift_timeout -= 5;
84 autoshift_timer_report();
87 #ifndef NO_AUTO_SHIFT_ALPHA
115 #ifndef NO_AUTO_SHIFT_NUMERIC
127 #ifndef NO_AUTO_SHIFT_SPECIAL
142 any_mod_pressed = get_mods() & (
143 MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
144 MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
145 MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
146 MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
149 if (any_mod_pressed) {
153 autoshift_on(keycode);