Hold and double tap

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

Hold and double tap

Postby fdg0d » Thu Jun 21, 2018 9:21 am

how do i run a combo when i hold A and double tap spacebar? i cant get it to work
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Re: Hold and double tap

Postby J2Kbr » Thu Jun 21, 2018 3:47 pm

The spacebar is mapped to a controller button? if yes please let me know to which button (X, Y, etc) because in this case would be very simple detect the double tap.
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: Hold and double tap

Postby fdg0d » Thu Jun 21, 2018 4:42 pm

no im using the USB multi interface HID
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Re: Hold and double tap

Postby J2Kbr » Fri Jun 22, 2018 7:54 am

Okay, so we need implement the double tap detection with script code, this will do for spacebar:
Code: Select all
#include <keyboard.gph>
 
bool spacebar_prev;
uint32 spacebar_active_ts;
uint32 spacebar_release_ts;
 
main {
    if(key_status(KEY_SPACEBAR)) {
        if(!spacebar_prev) {
            spacebar_active_ts = system_time();
            spacebar_prev = TRUE;
            // Check double tap
            if(system_time() - spacebar_release_ts <= 200) {
                //
                // Run combo from here
                //
            }
        }
    } else {
        if(spacebar_prev) {
            spacebar_release_ts = system_time();
            spacebar_prev = FALSE;
        }
    }
}
 
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: Hold and double tap

Postby fdg0d » Fri Jun 22, 2018 11:00 am

its working but how can i make it so when i hold the KEY_A on my keyboard and double press space to run the combo
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Re: Hold and double tap

Postby fdg0d » Fri Jun 22, 2018 12:03 pm

ive got this but now the doulbe tap doesnt work anymore
Code: Select all
#include <keyboard.gph>
#include <mouse.gph>
 
bool DASH;
bool spacebar_prev;
bool event_press_l;
uint32 spacebar_active_ts;
uint32 spacebar_release_ts;
 
init {
    mousemapping();
}
 
 
 
 
 
main {
    mouse_passthru();
    key_passthru();
 
    if(key_status(KEY_L)) {     
        if(!event_press_l) {
            event_press_l = TRUE;
            DASH = !DASH;
        }
    } else event_press_l = FALSE;
 
    if(DASH) {
 
    if(key_status(KEY_D) && key_status(KEY_SPACEBAR)) {
        if(!spacebar_prev) {
            spacebar_active_ts = system_time();
            spacebar_prev = TRUE;
            // Check double tap
            if(system_time() - spacebar_release_ts <= 200) {
                //
                combo_run(right);
                //
            }
        }
    } else {
        if(spacebar_prev) {
            spacebar_release_ts = system_time();
            spacebar_prev = FALSE;
        }
    }
 
 
if(key_status(KEY_A) && key_status(KEY_SPACEBAR)) {
        if(!spacebar_prev) {
            spacebar_active_ts = system_time();
            spacebar_prev = TRUE;
            // Check double tap
            if(system_time() - spacebar_release_ts <= 200) {
                //
                combo_run(left);
                //
            }
        }
    } else {
        if(spacebar_prev) {
            spacebar_release_ts = system_time();
            spacebar_prev = FALSE;
        }
    }
}
 
}
 
 
 
 
 
combo right {
    mouse_set(MOUSE_X, 100);
    wait(109);
    key_set(KEY_LEFTSHIFT, 1);
    wait(40);
    key_set(KEY_LEFTSHIFT, 0);
    wait(10);
    mouse_set(MOUSE_X, -100);
    wait(129);
    key_set(KEY_LEFTSHIFT, 0);
}
 
combo left {
    mouse_set(MOUSE_X, -100);
    wait(109);
    key_set(KEY_LEFTSHIFT, 1);
    wait(40);
    key_set(KEY_LEFTSHIFT, 0);
    wait(10);
    mouse_set(MOUSE_X, 100);
    wait(129);
    key_set(KEY_LEFTSHIFT, 0);
}
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm

Re: Hold and double tap

Postby Scachi » Fri Jun 22, 2018 2:25 pm

You can't use the space doubletap code twice or you will always reset the doubletap check if you are not pressing d+space and a+space at the same time.

You can put the space check at the first check and set a dblspace flag and use that flag in multiple checks like this:

Code: Select all
#include <keyboard.gph>
#include <mouse.gph>
 
bool DASH;
bool spacebar_prev;
bool dblspace = FALSE;
bool event_press_l;
uint32 spacebar_active_ts;
uint32 spacebar_release_ts;
 
 
init {
    mousemapping();
}
 
 
 
 
 
main {
    mouse_passthru();
    key_passthru();
 
    if(key_status(KEY_SPACEBAR)) {
        if(!spacebar_prev) {
            spacebar_active_ts = system_time();
            spacebar_prev = TRUE;
            // Check double tap
            if(system_time() - spacebar_release_ts <= 200) {
                //
                dblspace = TRUE;
                //
            }
        }
    } else {
        if(spacebar_prev) {
            spacebar_release_ts = system_time();
            spacebar_prev = FALSE;
        }
        dblspace = FALSE;
    }
 
    if(key_status(KEY_L)) {     
        if(!event_press_l) {
            event_press_l = TRUE;
            DASH = !DASH;
            printf("dash flag changed");
        }
    } else event_press_l = FALSE;
 
    if(DASH) {
 
      if(key_status(KEY_D) && dblspace) {
       combo_run(right);   
      }
 
 
      if(key_status(KEY_A) && dblspace ) {
        combo_run(left);
      }
  }
}
 
 
 
 
 
combo right {
    printf("right");
    wait(0);
    mouse_set(MOUSE_X, 100);
    wait(109);
    key_set(KEY_LEFTSHIFT, 1);
    wait(40);
    key_set(KEY_LEFTSHIFT, 0);
    wait(10);
    mouse_set(MOUSE_X, -100);
    wait(129);
    key_set(KEY_LEFTSHIFT, 0);
}
 
combo left {
    printf("left");
    wait(0);
    mouse_set(MOUSE_X, -100);
    wait(109);
    key_set(KEY_LEFTSHIFT, 1);
    wait(40);
    key_set(KEY_LEFTSHIFT, 0);
    wait(10);
    mouse_set(MOUSE_X, 100);
    wait(129);
    key_set(KEY_LEFTSHIFT, 0);
}
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Hold and double tap

Postby fdg0d » Fri Jun 22, 2018 5:27 pm

TY that works!
User avatar
fdg0d
Sergeant Major
Sergeant Major
 
Posts: 83
Joined: Thu May 12, 2016 3:16 pm


Return to GPC2 Script Programming

Who is online

Users browsing this forum: Baidu [Spider] and 114 guests