Martin
Martin

Reputation: 1

Delay RButton after LButton

I run an application that drops a RButton that is too soon after an LButton. The solution may be to run something like

~LButton::                    ; pass through, set A_PriorHotkey
return

#If A_PriorHotkey = LButton && A_TimeSincePriorHotkey < minDelay
RButton:: 

but I'm having no luck in writing the last line and following lines so that a normal MButton down and RButton up are sent if the the #IF is false or delay about 100ms then send RButton down and RButton up if the #IF is true.

Thanks in advance.

Upvotes: 0

Views: 382

Answers (2)

Robert Ilbrink
Robert Ilbrink

Reputation: 7953

From your description, I assume that you can not change the sending application (i.e. not an AutoHotKey script, but maybe a compiled ahk.exe)

Once you have been able to trigger AutoHotKey with the:

RButton::
    SoundBeep, 500,500
Return  

You can try this code:

SetTitleMatchMode = 2

#IfWinActive, Name of your Application
    $RButton::
       if (A_PriorHotkey = "LButton" AND A_TimeSincePriorHotkey < 400)
          Sleep, 1000
       Click, Right
    Return
#IfWinActive

You can find the name of the (sending or receiving application, depends on which one is active at that time), by right-clicking on the AutoHotKey icon, then launch Windows Spy. With Windows Spy active, click on the application and look at the title of the application (or the ahk_class).

Warning I have not tested this code!

Upvotes: 0

user1944441
user1944441

Reputation:

Here is a solution that should work, i tested it a bit and it should work 100% of the time. If you use it please don't just copy and paste but try to understand what the code does.

Basically what we do is on left click we time until we reach a certain time( in this case 1000 ms -> IGNORE_TIME) and in the meantime we ignore the rightclick, when the time is up right click is active again.

global IGNORE_TIME := 1000  ; ignore for 1000 miliseconds, change only this if you wan't different times
global starttime := 0


~LButton::
    SetTimer, DelayRButton_r ,Off
    starttime := 25
    SetTimer, DelayRButton_r ,25
    tooltip,leftbutton    ; debug
return


RButton::
    if(starttime > 0)    ; if the left button was pressed IGNORE_TIME ago or less ignore right click
        return
    Send, {RButton}    ; else send right click
    tooltip,rightbutton    ; debug
return


DelayRButton_r:    ; this function runs every 25 ms until it reaches IGNORE_TIME then if sets starttime to 0 and rightclick works again
    starttime += 25
    if( starttime > IGNORE_TIME)
    {
        SetTimer,DelayRButton_r, Off
        starttime := 0
    }
return

Also keep in mind this code can easily be edited to work only for a specific application/window.

Upvotes: 1

Related Questions