How to identify signle, double tap and long hold separately?

GPC2 script programming for Titan Two. Code examples, questions, requests.

How to identify signle, double tap and long hold separately?

Postby DrNefario » Sun Oct 25, 2020 10:28 pm

Hello guys, I am trying to utilize the function of a single bottom as much as possible,
So i wish to detect single, double tap and long hold separately, how can i do that?

I know i can use
Code: Select all
if (event_active(BUTTON_2) && time_release(BUTTON_2)<=200){

Something like this to detect a bouble tap, but how can i distinguish it with a simple single tap?
User avatar
DrNefario
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Sun Dec 30, 2018 12:04 pm

Re: How to identify signle, double tap and long hold separat

Postby J2Kbr » Tue Oct 27, 2020 11:09 am

Here is an example on how you can implement this.
Code: Select all
#define BUTTON              BUTTON_2
 
#define ACTION_NONE         0
#define ACTION_HOLD         1
#define ACTION_SINGLE_TAP   2
#define ACTION_DOUBLE_TAP   3
 
uint8 triggered_action;
uint8 process_action;
 
main {
    if(!process_action) {
        if(event_active(BUTTON)) {
            triggered_action = ACTION_SINGLE_TAP;
            if(time_release(BUTTON) < 150) {
                triggered_action = ACTION_DOUBLE_TAP;
                process_action = TRUE;
            }
        }
        if(triggered_action == ACTION_SINGLE_TAP) {
            if(check_release(BUTTON, 175)) {
                process_action = TRUE;
            }
        }
        if(check_active(BUTTON, 200)) {
            triggered_action = ACTION_HOLD;
            process_action = TRUE;
        }
    } else if(check_release(BUTTON, 250)) {
        process_action = FALSE;
    }
    if(process_action) {
        switch(triggered_action) {
            case ACTION_HOLD: {
                //
                // TODO Hold action
                //
            } break;
            case ACTION_SINGLE_TAP: {
                //
                // TODO Single-tap action
                //
            } break;
            case ACTION_DOUBLE_TAP: {
                //
                // TODO Double-tap action
                //
            } break;
        }
        triggered_action = ACTION_NONE;
    }
}
 
ConsoleTuner Support Team
User avatar
J2Kbr
General of the Army
General of the Army
 
Posts: 20323
Joined: Tue Mar 18, 2014 1:39 pm

Re: How to identify signle, double tap and long hold separat

Postby DrNefario » Tue Oct 27, 2020 1:26 pm

J2Kbr wrote:Here is an example on how you can implement this.
Code: Select all
#define BUTTON              BUTTON_2
 
#define ACTION_NONE         0
#define ACTION_HOLD         1
#define ACTION_SINGLE_TAP   2
#define ACTION_DOUBLE_TAP   3
 
uint8 triggered_action;
uint8 process_action;
 
main {
    if(!process_action) {
        if(event_active(BUTTON)) {
            triggered_action = ACTION_SINGLE_TAP;
            if(time_release(BUTTON) < 150) {
                triggered_action = ACTION_DOUBLE_TAP;
                process_action = TRUE;
            }
        }
        if(triggered_action == ACTION_SINGLE_TAP) {
            if(check_release(BUTTON, 175)) {
                process_action = TRUE;
            }
        }
        if(check_active(BUTTON, 200)) {
            triggered_action = ACTION_HOLD;
            process_action = TRUE;
        }
    } else if(check_release(BUTTON, 250)) {
        process_action = FALSE;
    }
    if(process_action) {
        switch(triggered_action) {
            case ACTION_HOLD: {
                //
                // TODO Hold action
                //
            } break;
            case ACTION_SINGLE_TAP: {
                //
                // TODO Single-tap action
                //
            } break;
            case ACTION_DOUBLE_TAP: {
                //
                // TODO Double-tap action
                //
            } break;
        }
        triggered_action = ACTION_NONE;
    }
}
 



Thank you so much! BTW, i have updated my anti-recoil algorithm, it is really good!
Check this link if you are interested. I have uploaded the source code in the comment.

viewtopic.php?f=23&t=16612&start=10

Thanks again for all the help!
User avatar
DrNefario
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Sun Dec 30, 2018 12:04 pm

Re: How to identify signle, double tap and long hold separat

Postby Kidd23 » Sun Nov 01, 2020 9:35 pm

Is it possible to get a T1 version of this code? Would be helpful
User avatar
Kidd23
Sergeant First Class
Sergeant First Class
 
Posts: 16
Joined: Wed Dec 19, 2018 6:50 pm

Re: How to identify signle, double tap and long hold separat

Postby teddy18 » Mon Apr 26, 2021 9:38 pm

Can I use this script for joy con

I want to map button to keyboard keys

If prese Button Y. Get Key R

If I hold Button Y get key. f
User avatar
teddy18
Lieutenant
Lieutenant
 
Posts: 346
Joined: Sun Jul 19, 2015 4:18 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: kubawaz and 111 guests