HID Scripting help needed

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

Re: HID Scripting help needed

Postby TT3000 » Tue Jan 26, 2021 5:21 pm

oh great
how do i add this into my script?
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby TT3000 » Tue Jan 26, 2021 5:33 pm

oh this is genius
i have figured it out
amazing
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby TT3000 » Tue Jan 26, 2021 6:07 pm

how do I code if I include the ps3 navigation as well now?
can they cross talk? for example, can I say "if get_val(button_3) & mouse_event_active(MBUTTON_1) run combo" ?
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby Scachi » Tue Jan 26, 2021 7:14 pm

yes, you can combine them. you have to select the function according to the type of the input or the output.
So if you want to read the input of a controller use "get_val" and all the normal functions.
For output with HID mode it depends on the output:
If you want to output as keyboard use key_set if your want to output as mouse use mouse_set, if you want to output as joystick (not console compatible gamepad) use set_val.
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: HID Scripting help needed

Postby TT3000 » Thu Feb 04, 2021 2:29 am

HEY SACHI
sorry been away on work
thank you for the explanation that cleared it up a lot.
so I got the recoil just right and even managed to make rapid-fire mode work but I got two issues.
1. is trying to map wasd to the stick_2 (it only seems to go forward if I move the stick forward or backwards) i used to be able to define it using > 90 or <80.
2. is id like to activate the combo only if a button is held for a period of time for example [ if (get_val(PS4_L2) && (get_ptime(PS4_L2) >= 70)) {combo_run(c_HB);}]

here is my attempt so far

Code: Select all
#pragma METAINFO("USH-HID_AntiRecoil_Fix32 Extended", 1, 0, "Scachi")
#include <keyboard.gph>
#include <mouse.gph>
#include <mouse_events.gph>
#include <key_events.gph>
 
// configuration
// advanced configuration
const int MOUSE_SPEED = 10; // <- should be around 10 or higher, a value too low can stop the mouse from working
 
// internal
fix32 antirecoil_X;
fix32 antirecoil_Y;
uint32 ARTIMER;
int32 X, Y, WHEEL;
int32 RX, RY;
fix32 ARX, ARY;
 
// mouse press time tracker for staged anti recoil
uint32 mb1timer;
 
init {
    port_connect(PORT_USB_C, PROTOCOL_HID);
    keymapping();
    mousemapping();
}
 
main {
    key_passthru();
    mouse_passthru();
 
    X = 0; Y = 0; WHEEL = 0;
    RX = 0; RY = 0;
 
    if(mouse_status(MREPORT_UPDATED)) {
        mouse_passthru(); // only passthru when there is data to send
        X = mouse_status(MOUSE_X);
        Y = mouse_status(MOUSE_Y);
        WHEEL = mouse_status(MOUSE_WHEEL);
    }
 
    if(mouse_status(MBUTTON_1))
    {
        ARTIMER += elapsed_time(); // mouse speed timer
 
 
        mb1timer += elapsed_time(); // mouse button press timer
 
        // ADJUST VALUES & TIME and add more here as required
        // !! example only.. you need to retune the anti recoil values as gamepad values don't apply 1:1 to mouse values !!
        if (mb1timer < 95) { antirecoil_X = 1.0; antirecoil_Y = 2.0; }
        else if (mb1timer <  200) { antirecoil_X =  -0.2; antirecoil_Y = 3.0; }
        else if (mb1timer <  900) { antirecoil_X =  -0.55; antirecoil_Y = 3.0; }
        else if (mb1timer < 1300) { antirecoil_X = -0.55; antirecoil_Y = 3.0; }
        else if (mb1timer < 5000) { antirecoil_X = -0.55; antirecoil_Y = 3.0; }
        else if (mb1timer < 6000) { antirecoil_X = -100.55; antirecoil_Y = 2.0; }
 
 
        if(!(ARTIMER%MOUSE_SPEED)) {
 
            ARX += (fix32)(antirecoil_X);
            ARY += (fix32)(antirecoil_Y);
 
            if (antirecoil_X < 0.0) RX += (int)ceil((ARX));
            else RX += (int)floor((ARX));
 
            if (antirecoil_Y < 0.0) RY += (int)ceil((ARY));
            else RY += (int)floor((ARY));
 
            mouse_set(MOUSE_X, X+RX);
            mouse_set(MOUSE_Y, Y+RY);
            mouse_set(MOUSE_WHEEL,WHEEL);
            ARX = mod(ARX,1.0);
            ARY = mod(ARY,1.0);
        }
    } else {
        ARTIMER = MOUSE_SPEED; // reset mouse speed timer
        ARX = 0.0; ARY = 0.0;
        mb1timer = 0; // reset mouse button press timer
    }
    if(mouse_event_active(MBUTTON_1)) {
        combo_run(ping);}
 
    if(mouse_status(MBUTTON_1)) {
        combo_run(RF);}
 
        if (get_val(STICK_2_Y)) {
        combo_run(W);}
 
}
 
combo ping {
 
    key_set(KEY_LEFTALT, 100);
    wait(30);
    key_set(KEY_LEFTALT, 0);
    wait(80);
    key_set(KEY_LEFTALT, 100);
    wait(30);
    key_set(KEY_LEFTALT, 0);
    wait(1000);
}
 
 combo RF {
    mouse_set(MBUTTON_1, 100);
    wait(20);
    mouse_set(MBUTTON_1, 0);
    wait(20);
}
 combo W {
    key_set(KEY_W, 100);
 
}
 


bonus question (if i may be cheeky) how do i block input for certain time like if(get_val(PS4_L2)) {
block(PS4_L3, 320);}
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby Scachi » Thu Feb 04, 2021 9:05 am

Take a look at the device monitor when you move the stick.
Up is Y < 0, Down is Y > 0, left is X < 0 and right is X > 0.
You want to add some deadzone to that to make sure to trigger moving in a direction/pressing only a key when you are moving the stick more than 8.0 or something in a direction.

Code: Select all
if(get_actual(STICK_2_Y) < -8.0) {
  ... press key for up
}
if(get_actual(STICK_2_Y) > 8.0) {
  ...press key for down
}
 


you can give the "inhibit" function a try to block the output of a button for some specific time.
Code: Select all
 if(get_val(BUTTON_8)) inhibit(BUTTON_9,320);

or use some combination of time_active and get_val or check_active. Then use set_val(BUTTTON_NR,0); to set that button for that time check to unpressed.
Code: Select all
if (! check_active(BUTTON_8,320)) set_val(BUTTON_9,0);

all code untested so you have all the fun ;-)
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: HID Scripting help needed

Postby TT3000 » Thu Feb 04, 2021 11:37 am

thank you so much scachi i will try em all out.
i also looked into your other works
some of the mods you've done are crazyyyyy
especially the 3d printed stuff
keep up the great work :)
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby TT3000 » Thu Feb 04, 2021 4:32 pm

Hey, so I've been playing around with the codes for a few hours now and got the whole gamepad mapped out thank you.
but how do I add timed button press events? such as if I press and hold key_W for 50ms deactivate or ignore key_W and activate key_M or activate a combo for instance?
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby TT3000 » Thu Feb 04, 2021 5:53 pm

Ignore me i just discovered the xkeys you were talking about
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

Re: HID Scripting help needed

Postby TT3000 » Thu Feb 04, 2021 6:57 pm

the script is almost ready but
Code: Select all
 
in testing, I noticed that it was harder to navigate menus with the Anti recoil on.
is there some way I could disable it if I hold down a button say (Key_Y)? So I could hold the key Y for navigating menu.

also, could I get this combo to run only when I fully press the forward key but the combo should only run once?
I tried all the codes you've shown so far and no luck
Code: Select all
if(get_actual(STICK_2_Y) < -98.0) {
        combo_run(TS);}


here is the full script so far

Code: Select all
#pragma METAINFO("Mouse Amax", 1, 0, "Scachi")
#include <keyboard.gph>
#include <mouse.gph>
#include <mouse_events.gph>
#include <key_events.gph>
#include <ps4.gph>
#define XKEYS_TO_MONITOR_MAX 5 // change 2 to the maximum number of keys you want to keep track of
#include "xkeys.gph"
 
// configuration
// advanced configuration
const int MOUSE_SPEED = 10; // <- should be around 10 or higher, a value too low can stop the mouse from working
 
// internal
fix32 antirecoil_X;
fix32 antirecoil_Y;
uint32 ARTIMER;
int32 X, Y, WHEEL;
int32 RX, RY;
fix32 ARX, ARY;
 
 
// mouse press time tracker for staged anti recoil
uint32 mb1timer;
 
uint8 KEY1, KEY2; // or any other name, this will get an index number assigned by the xkeys_add function
 
 
init {
    port_connect(PORT_USB_C, PROTOCOL_HID);
    keymapping();
    mousemapping();
      // use xkeys_add to add each key to monitor, it returns an uint8 number that has to be used with the functions
  KEY1=xkeys_add(KEY_1); // add key KEY_A to monitoring
  KEY2=xkeys_add(KEY_F); // add key KEY_S to monitoring
 
}
 
main {
    key_passthru();
    mouse_passthru();
 
    X = 0; Y = 0; WHEEL = 0;
    RX = 0; RY = 0;
 
    if(mouse_status(MREPORT_UPDATED)) {
        mouse_passthru(); // only passthru when there is data to send
        X = mouse_status(MOUSE_X);
        Y = mouse_status(MOUSE_Y);
        WHEEL = mouse_status(MOUSE_WHEEL);
    }
 
    if(mouse_status(MBUTTON_1))
    {
        ARTIMER += elapsed_time(); // mouse speed timer
 
 
        mb1timer += elapsed_time(); // mouse button press timer
 
        // ADJUST VALUES & TIME and add more here as required
        // !! example only.. you need to retune the anti recoil values as gamepad values don't apply 1:1 to mouse values !!
        if (mb1timer < 95) { antirecoil_X = 2.0; antirecoil_Y = 5.0; }
        else if (mb1timer <  300) { antirecoil_X =  -0.0; antirecoil_Y = 8.0; }
        else if (mb1timer <  900) { antirecoil_X =  -0.0; antirecoil_Y = 8.0; }
        else if (mb1timer < 1300) { antirecoil_X = -0.55; antirecoil_Y = 3.0; }
        else if (mb1timer < 5000) { antirecoil_X = -0.55; antirecoil_Y = 3.0; }
        else if (mb1timer < 6000) { antirecoil_X = -0.55; antirecoil_Y = 3.0; }
 
 
        if(!(ARTIMER%MOUSE_SPEED)) {
 
            ARX += (fix32)(antirecoil_X);
            ARY += (fix32)(antirecoil_Y);
 
            if (antirecoil_X < 0.0) RX += (int)ceil((ARX));
            else RX += (int)floor((ARX));
 
            if (antirecoil_Y < 0.0) RY += (int)ceil((ARY));
            else RY += (int)floor((ARY));
 
            mouse_set(MOUSE_X, X+RX);
            mouse_set(MOUSE_Y, Y+RY);
            mouse_set(MOUSE_WHEEL,WHEEL);
            ARX = mod(ARX,1.0);
            ARY = mod(ARY,1.0);
        }
    } else {
        ARTIMER = MOUSE_SPEED; // reset mouse speed timer
        ARX = 0.0; ARY = 0.0;
        mb1timer = 0; // reset mouse button press timer
    }
 
    //PING
    if(mouse_event_active(MBUTTON_1)) {
        combo_run(ping);}
 
    //RAPID FIRE   
    if(key_status(KEY_Y) & (mouse_status(MBUTTON_1))) {
        combo_run(RF);}
 
    //    RELOAD & ACTION
    if (xkeys_is_active(KEY2) && xkeys_time_active(KEY2) > 300) {
        key_set(KEY_R, 100);}
 
    //TAC SPRINT   
    if(event_active (STICK_2_Y)) {
        combo_run(TS);}
 
    //weapon switch & armor key
    if (xkeys_is_active(KEY1) && xkeys_time_active(KEY1) > 200) {
        key_set(KEY_1, 0);
        key_set(KEY_4, 100);}
 
 
// REMAPING
 
    // STICK FORWARD
    if(get_actual(STICK_2_Y) < -20.0) {
        key_set(KEY_W, 100);}
 
    if(get_actual(STICK_2_Y) < -98.0) {
        key_set(KEY_LEFTSHIFT , 100);}
    // STICK BACKWARD   
    if(get_actual(STICK_2_Y) > 50.0) {
        key_set(KEY_S, 100);}
    // STICK RIGHT
    if(get_actual(STICK_2_X) > 50.0) {
        key_set(KEY_D, 100);}
    // STICK LEFT
    if(get_actual(STICK_2_X) < -50.0) {
        key_set(KEY_A, 100);}
 
    // PS3 NAV L2   
    if(get_val(BUTTON_8)) {
        key_set(KEY_SPACEBAR, 100);}
 
    // PS3 NAV L1   
    if(get_val(BUTTON_7)) {
        key_set(KEY_C, 100);}
 
    // PS3 NAV L3   
    if(get_val(BUTTON_9)) {
        key_set(KEY_LEFTSHIFT, 0);}
 
    // PS3 NAV CIRCLE   
    if(get_val(BUTTON_15)) {
        key_set(KEY_ESCAPE, 100);}
 
    // PS3 NAV CROSS   
    if(get_val(BUTTON_16)) {
        key_set(KEY_RETURNORENTER, 100);}
 
    // PS3 NAV PS BUTTON   
    if(get_val(BUTTON_1)) {
        key_set(KEY_M, 100);}
 
    // PS3 NAV DOWN   
    if(get_val(BUTTON_11)) {
        key_set(KEY_L, 100);}
 
    // PS3 NAV UP   
    if(get_val(BUTTON_10)) {
        key_set(KEY_LEFTALT, 100);}
 
    // PS3 NAV RIGHT   
    if(get_val(BUTTON_13)) {
        key_set(KEY_3, 100);}
 
    // PS3 NAV LEFT   
    if(get_val(BUTTON_12)) {
        key_set(KEY_M, 0);}
}
 
combo ping {
 
    key_set(KEY_LEFTALT, 100);
    wait(30);
    key_set(KEY_LEFTALT, 0);
    wait(80);
    key_set(KEY_LEFTALT, 100);
    wait(30);
    key_set(KEY_LEFTALT, 0);
    wait(1000);
}
 
 combo RF {
    mouse_set(MBUTTON_1, 100);
    wait(20);
    mouse_set(MBUTTON_1, 0);
    wait(20);
}
combo TS {
 
    key_set(KEY_LEFTSHIFT, 100);
    wait(10);
    key_set(KEY_LEFTSHIFT, 0);
    wait(20);
    key_set(KEY_LEFTSHIFT, 100);
    wait(10);
    key_set(KEY_LEFTSHIFT, 0);
    wait(20);
}
 
User avatar
TT3000
Master Sergeant
Master Sergeant
 
Posts: 35
Joined: Fri Nov 20, 2020 7:58 pm

PreviousNext

Return to GPC2 Script Programming

Who is online

Users browsing this forum: AZOV_ops and 119 guests