tmk / tmk_keyboard

Keyboard firmwares for Atmel AVR and Cortex-M
3.99k stars 1.71k forks source link

What is the difference between the ACTION_FUNCTION_TAP and ACTION_FUNCTION? #369

Closed chenzhihuai1990 closed 8 years ago

chenzhihuai1990 commented 8 years ago

Hi tmk, It is an amazing project, so that I can't wait to make my keymap for my HHKB.

However, since I am not familiar with controller, I have a question about it.

Dose ACTION_FUNCTION_TAP mean that the controller will listen to the event of tapping correspond key? In Fact, I want to implement a smart alt key as following:

1). Once H,J,K,L is typed with ALT pressed, it move the cursor as vi; 2). Once Tabis typed with ALTpressed, the switcher show up and keep visible until ALTis released; 3). Once Altis tapped, it send an alt_released event(in Windows, it active the menu).

...
[2] = ACTION_FUNCTION_TAP(ALT_FN) // assume `ALT `is mapping to FN2
...
[3] = ACTION_FUNCTION(TAB_FN)// assume Tab is mapping to FN3 in LAYER_2
...

static bool isAltTabActived=false;
void action_function(keyrecord_t *record, uint8_t id, uint8_t opt)
{
    switch (id) {
         case ALT_FN:
            if (record.event.pressed) {
                layer_on(2);
            }
            else {
                layer_off(2);

                if (record.tap.count>0 || isAltTabActived){
                    /*Alt released!*/
                }
                isAltTabActived=false;
            }

        case TAB_FN: 
            if (record.event.pressed) {
                if (!isAltTabActived){
                    isAltTabActived=true;
                    /*Alt Pressed, Tab Pressed, Tab Released*/
                }else {
                    /*Tab Pressed, Tab Released*/
                }
            }
    }
}
tmk commented 8 years ago

ACTION_FUNCTION_TAP is handled as a tap key, namely record->tap.count and record->tap.interrupted are available for it.