aboutsummaryrefslogtreecommitdiff
path: root/quantum/process_keycode/process_auto_shift.c
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/process_auto_shift.c
parent87021371e6273258a9385a0a5ed4cfd344f9de8f (diff)
downloadqmk_firmware-abba393f57fdfb9b7abd92cc7925a605619902b2.tar.gz
qmk_firmware-abba393f57fdfb9b7abd92cc7925a605619902b2.zip
Added Auto Shift, tap key = normal, hold key = shifted state.
Diffstat (limited to 'quantum/process_keycode/process_auto_shift.c')
-rw-r--r--quantum/process_keycode/process_auto_shift.c168
1 files changed, 168 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 000000000..55b524450
--- /dev/null
+++ b/quantum/process_keycode/process_auto_shift.c
@@ -0,0 +1,168 @@
1/* Copyright 2017 Jeremy Cowgar
2 *
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.
7 *
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.
12 *
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/>.
15 */
16
17#ifdef AUTO_SHIFT_ENABLE
18
19#include <stdio.h>
20
21#include "process_auto_shift.h"
22
23#define TAP(key) \
24 register_code(key); \
25 unregister_code(key)
26
27#define TAP_WITH_MOD(mod, key) \
28 register_code(mod); \
29 register_code(key); \
30 unregister_code(key); \
31 unregister_code(mod)
32
33uint16_t autoshift_time = 0;
34uint16_t autoshift_timeout = AUTO_SHIFT_TIMEOUT;
35uint16_t autoshift_lastkey = KC_NO;
36
37void autoshift_timer_report(void) {
38 char display[8];
39
40 snprintf(display, 8, "\n%d\n", autoshift_timeout);
41
42 send_string((const char *)display);
43}
44
45void autoshift_on(uint16_t keycode) {
46 autoshift_time = timer_read();
47 autoshift_lastkey = keycode;
48}
49
50void autoshift_flush(void) {
51 if (autoshift_lastkey != KC_NO) {
52 uint16_t elapsed = timer_elapsed(autoshift_time);
53
54 if (elapsed > autoshift_timeout) {
55 register_code(KC_LSFT);
56 }
57
58 register_code(autoshift_lastkey);
59 unregister_code(autoshift_lastkey);
60
61 if (elapsed > autoshift_timeout) {
62 unregister_code(KC_LSFT);
63 }
64
65 autoshift_time = 0;
66 autoshift_lastkey = KC_NO;
67 }
68}
69
70bool process_auto_shift(uint16_t keycode, keyrecord_t *record) {
71 static uint8_t any_mod_pressed;
72
73 if (record->event.pressed) {
74 switch (keycode) {
75 case KC_ASUP:
76 autoshift_timeout += 5;
77 return false;
78
79 case KC_ASDN:
80 autoshift_timeout -= 5;
81 return false;
82
83 case KC_ASRP:
84 autoshift_timer_report();
85 return false;
86
87#ifndef NO_AUTO_SHIFT_ALPHA
88 case KC_A:
89 case KC_B:
90 case KC_C:
91 case KC_D:
92 case KC_E:
93 case KC_F:
94 case KC_G:
95 case KC_H:
96 case KC_I:
97 case KC_J:
98 case KC_K:
99 case KC_L:
100 case KC_M:
101 case KC_N:
102 case KC_O:
103 case KC_P:
104 case KC_Q:
105 case KC_R:
106 case KC_S:
107 case KC_T:
108 case KC_U:
109 case KC_V:
110 case KC_W:
111 case KC_X:
112 case KC_Y:
113 case KC_Z:
114#endif
115#ifndef NO_AUTO_SHIFT_NUMERIC
116 case KC_1:
117 case KC_2:
118 case KC_3:
119 case KC_4:
120 case KC_5:
121 case KC_6:
122 case KC_7:
123 case KC_8:
124 case KC_9:
125 case KC_0:
126#endif
127#ifndef NO_AUTO_SHIFT_SPECIAL
128 case KC_TILD:
129 case KC_MINUS:
130 case KC_EQL:
131 case KC_TAB:
132 case KC_LBRC:
133 case KC_RBRC:
134 case KC_BSLS:
135 case KC_SCLN:
136 case KC_QUOT:
137 case KC_COMM:
138 case KC_DOT:
139 case KC_SLSH:
140#endif
141 autoshift_flush();
142
143 any_mod_pressed = get_mods() & (
144 MOD_BIT(KC_LGUI)|MOD_BIT(KC_RGUI)|
145 MOD_BIT(KC_LALT)|MOD_BIT(KC_RALT)|
146 MOD_BIT(KC_LCTL)|MOD_BIT(KC_RCTL)|
147 MOD_BIT(KC_LSFT)|MOD_BIT(KC_RSFT)
148 );
149
150 if (any_mod_pressed) {
151 return true;
152 }
153
154 autoshift_on(keycode);
155 return false;
156
157 default:
158 autoshift_flush();
159 return true;
160 }
161 } else {
162 autoshift_flush();
163 }
164
165 return true;
166}
167
168#endif