Correct way to use mouse wheels?

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

Correct way to use mouse wheels?

Postby pablosscripts » Sun Jun 16, 2019 1:24 pm

I'm using the following code. I originally made it so when you scroll, it triggers a key press. However that didn't work very well, it was very glitchy if you were trying to scroll more than once, so I tried using a combo with a wait timer on it like this:

Code: Select all
main {
    if(mouse_status(WHEEL_UP) == 1) {
        if(is_scrolled_up) {
            combo_run(SecondaryForce);
            // key_set(SECONDARY, TRUE);
            is_scrolled_up = 0;
        }
    } else {
        is_scrolled_up = 1;
    }
 
    if(mouse_status(WHEEL_DOWN) == -1) {
        if(is_scrolled_down) {
            combo_run(PrimaryForce);
            // key_set(PRIMARY, TRUE);
            is_scrolled_down = 0;
        }
    } else {
        is_scrolled_down = 1;
    }
}
 
combo PrimaryForce {
    key_set(PRIMARY, TRUE);
    wait(100);
}
 
combo SecondaryForce {
    key_set(SECONDARY, TRUE);
    wait(100);
}


This works a little better but it's a bit glitchy too. It works perfectly for the first "press" but when I try to scroll up a few times in quick succession to press the button repeatedly it doesn't work well. What am I doing wrong?
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am

Re: Correct way to use mouse wheels?

Postby Scachi » Sun Jun 16, 2019 1:57 pm

You can adjust the time in TLIMIT to register a scroll in the same direction as a new scroll faster:
Code: Select all
#include <mouse.gph>
 
#define TLIMIT    200        // idle time after a scroll in the same direction will be accepted as a new scroll
uint32 scrollTstamp;         // last time a scroll was used
int8     scrollDir;         // last direction of scroll
 
main {
  mouse_wheel();
}
 
void mouse_wheel() {
  int8 wheel;
    uint32 tstamp;
 
  if (mouse_status(MREPORT_UPDATED)) {
    if (wheel=mouse_status(MOUSE_WHEEL)) {
            tstamp=mouse_status(MREPORT_TIMESTAMP);
            if (wheel!=scrollDir || tstamp > scrollTstamp + TLIMIT) { // on direction change or current_time > lasttime+TLMIT a scroll will be accepted as a new scroll
                    printf("tstamp: %ld, scolltstamp: %ld , diff: %ld",tstamp,scrollTstamp,tstamp-scrollTstamp);
                    scrollDir=wheel;
                    if (wheel==1) printf("Mouse Wheel Forward");   
                    if (wheel==-1) printf("Mouse Wheel Backward");
            }
            scrollTstamp=tstamp;
    }
  }
}
 
 
User avatar
Scachi
Brigadier General
Brigadier General
 
Posts: 3044
Joined: Wed May 11, 2016 6:25 am
Location: Germany

Re: Correct way to use mouse wheels?

Postby pablosscripts » Sun Jun 16, 2019 3:02 pm

That's perfect. I adjusted the time to 100 and it works exactly as I'd want it to. Thanks!
Setup: XIM Apex, T2, K780 keyboard, G Pro Wireless mouse, SteelSeries 4HD pad, DXRacer armrest, LucidSound LS30 headset, Netduma router, Ubiquiti UniFi AP LR

My R6 script: https://youtu.be/x-9NtxyySVM
User avatar
pablosscripts
Brigadier General
Brigadier General
 
Posts: 1976
Joined: Tue Nov 24, 2015 6:27 am


Return to GPC2 Script Programming

Who is online

Users browsing this forum: No registered users and 119 guests