taphold.c (1112B)
1 #include "taphold.h" 2 #include "action_layer.h" 3 #include "keyboard.h" 4 #include "timer.h" 5 6 bool taphold_process(uint16_t keycode, keyrecord_t *record) { 7 for (int i = 0; i < taphold_config_size; i++) { 8 taphold_t *config = &taphold_config[i]; 9 if (config->key == keycode && record->event.pressed) { 10 if (config->mode == TAPHOLD_LAYER) { 11 layer_on(config->longAction); 12 } else { 13 register_code(config->longAction); 14 } 15 config->time = timer_read32(); 16 config->keypos = record->event.key; 17 return false; 18 } else if (KEYEQ(record->event.key, config->keypos) && !record->event.pressed) { 19 if (config->mode == TAPHOLD_LAYER) { 20 layer_off(config->longAction); 21 } else { 22 unregister_code(config->longAction); 23 } 24 if (timer_elapsed32(config->time) < taphold_timeout) { 25 tap_code(config->shortAction); 26 } 27 config->keypos.row = 255; 28 return false; 29 } 30 } 31 return true; 32 }