1 /* Copyright 2016 Jack Humbert
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 #include "process_chording.h"
19 bool keys_chord(uint8_t keys[]) {
20 uint8_t keys_size = sizeof(keys)/sizeof(keys[0]);
23 for (uint8_t i = 0; i < chord_key_count; i++) {
25 for (uint8_t j = 0; j < keys_size; j++) {
26 if (chord_keys[i] == (keys[j] & 0xFF)) {
27 in++; // detects key in chord
34 if (chord_keys[i] != 0) {
35 pass = false; // makes sure rest are blank
38 return (pass && (in == keys_size));
41 bool process_chording(uint16_t keycode, keyrecord_t *record) {
42 if (keycode >= QK_CHORDING && keycode <= QK_CHORDING_MAX) {
43 if (record->event.pressed) {
46 for (uint8_t i = 0; i < CHORDING_MAX; i++)
51 chord_keys[chord_key_count] = (keycode & 0xFF);
58 if (chord_key_down == 0) {
61 if (keys_chord((uint8_t[]){KC_ENTER, KC_SPACE})) {
63 unregister_code(KC_A);
66 for (uint8_t i = 0; i < chord_key_count; i++) {
67 register_code(chord_keys[i]);
68 unregister_code(chord_keys[i]);