I'm not a programmer and barely understand code, so I apologize in advance if I say or ask anything stupid here...
Right now I have this:
static const uint16_t PROGMEM fn_actions[] = {
[12] = ACTION_LAYER_TAP_KEY(2, KC_SLSH), // layer 2 with tap / and ?
};
and call the FN12 key in my keymap macro.
If I tap the FN12 key I get /, if I tap it while holding shift I get ?, and if I hold it I momentarily activate layer 2.
Okay, now instead I want it to work like this: a tap registers a ? and a hold still momentarily switches to layer 2. If I use ACTION_FUNCTION_TAP, does this look right for everything I need to add?
/*
* Fn action definition
*/
//change Fn12 to:
[12] = ACTION_LAYER_MOMENTARY(2) // not quite sure how to call the layer in the ACTION_FUNCTION_TAP - see below
//add this:
[13] = ACTION_FUNCTION_TAP(LAYER2_QMARK), // Function: Layer 2 with tap ?
// add everything below:
/* id for user defined functions */
enum function_id {
LAYER2_QMARK,
};
/*
* user defined action function
*/
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
keyevent_t event = record->event;
tap_t tap = record->tap;
switch (id) {
case LAYER2_QMARK: // Layer 2 + tap '?'
if (event.pressed) {
if (tap.count == 0 || tap.interrupted) { // will this work with a press and hold, like for momentary layer switching?
host_add_key(KC_FN12); // Can I call a Fn key with this function? How else would I switch the layer on?
} else {
host_add_mods(MOD_BIT(KC_LSHIFT));
host_add_key(KC_SLSH);
host_send_keyboard_report();
host_del_mods(MOD_BIT(KC_LSHIFT));
host_del_key(KC_SLSH);
host_send_keyboard_report();
}
} else {
if (tap.count == 0 || tap.interrupted) {
host_del_key(KC_FN12);
}
}
break;
}
}
I'm confused on how to call the layer. I'm sure I'm doing this wrong...Also, will the tap.count work if it's not a tap, but a press and hold? Is that what the 0 stands for...it registers the key pressed but not "tapped"
Does [if (tap.count == 0] mean that I could setup different actions for a different number of taps? For example, 0 taps (press and hold) momentarily switches layers, 1 tap registers a character, and 2 taps toggles a layer? I'm assuming it would just be a nested if statement?
if (tap.count == 0 || tap.interrupted) {
momentary switch layer
} elseif (tap.count == 2 || tap.interrupted) {
toggle layer
} else {
register character
Thanks for all the great help! I'm consistently amazed at all the functionality included in your firmware.