0
votes

I want to make a script that would allow me to click once every time I press the mouse, however, if instead of letting go immediately, I hold the RMB for more than 0.25s it would click again on release.

Essentially allowing me to use RMB normally as long as I don't hold it for too long but allowing me to do a double click if held.

This is a work around since my mouse's button gets stuck if I click too fast and I'm not able to get a new one atm.

The purpose of this is to be able to use my mouse on PS and to play the one game i play some times: Black Ops 2 while i save enough for a new mouse. In the context of the game, i want to be able to use Toggle ADS as a base and be able to use the toggle by default by just clicking but be able also do a Hold to ADS with the same button on the fly without changing the game's configuration.

I am not very proficient at AHK and this is all I got so far, holding works fine, however if I don't hold, it does a double click which is annoying.

RButton Down::
Send {Click, Right}
       keywait RButton, t.25
     if errorlevel
       keywait RButton, 
    Send {RButton Up} 
return
3
Do not write answers in questions please (post as separate answer). - user4157124

3 Answers

0
votes

It looks like you're missing some curly braces around your if block; but I think you can implement the right double-click functionality with something as simple as,

RButton::
  KeyWait RButton, T.25
  numberOfClicks := errorLevel + 1
  Send {Click Right %numberOfClicks%}
return
0
votes

You could maybe do some trickery with multiple KeyWaits, but I wouldn't recommend time consuming processing inside hotkey labels in any case due to AHKs single threaded nature.

Here's something very simple I'd recommend instead:

~*RButton::RClickTime := A_TickCount

~*RButton Up::
    if (A_TickCount - RClickTime >= 250)
        Click, Right
return

So first when we press down RButton (note that there is no "down" state for hotkey names, the key name itself means it being pressed down) we store the current system time with A_TickCount.
And we use the ~ modifier for the hotkey so the keypress itself isn't consumed.
And the * modifier is used so holding down e.g. Ctrl or Shift, etc, wouldn't make the hotkey not work.

Then on RButton release (RButton Up::) we compare the current system time with the stored system time to see if over 250ms passed. If so, we send another right click with Click, Right (don't use a send command here, it isn't really intended for this).

0
votes
~RButton:: ;*When Right Mouse Button is Down, do the following.*
keywait RButton, T.25 ;*Wait (250 milliseconds) for it to be released.*
if errorlevel { ;*When it exceeds the said time*
keywait RButton ;*Wait for it to be released*
Send, {RButton Up} ;*Send Right Mouse Button up*
}
return