How to check to see if I am holding down the right mouse button? Topic is solved

Ask gaming related questions (AHK v1.1 and older)
MantraHK
Posts: 6
Joined: 09 Mar 2024, 00:48

How to check to see if I am holding down the right mouse button?

07 Apr 2024, 02:27

Hi,

Does anyone know how to draft a script that will:
Check if I click and hold down the right mouse button for more than 3 seconds
If I do I would like the script to hold down the right mouse button for me even if I release the mouse button
until I click the right mouse button again then it can 'lift' the right mouse button


Here is a piece of code I was working with but it aint quite there.
If I use the same mouse button as the toggle it gets confused so I tried playing with using the rbutton to toggle the lbutton but idealy I would like it to just all be on the one.
Also not sure how to toggle it only after I hold down the mouse button.

Thanks in advance!

Code: Select all

#RButton::
8::
If (toggle := !toggle) {
 Send {LButton Down}
 SoundBeep, 250, 20
  
} Else {
 Send {LButton Up}
 SoundBeep, 500, 20
}
Return


PAUSE::ExitApp
[Mod edit: Added [code][/code] tags/replaced blue color tags around the code - which is almost unreadable in dark forum themes, btw. Please use code tags yourself when posting code!]
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: How to check to see if I am holding down the right mouse button?

07 Apr 2024, 06:39

Code: Select all

#Requires AutoHotkey v1.1.33.11

RButton::
KeyWait RButton, T3
Switch ErrorLevel GetKeyState("RButton") {
 Case  0: Click R
 Case 10: Click R D
 Default: Click R U
}
SoundBeep 1000 + 500 * GetKeyState("RButton")
Return
Explained: KeyWaitGetKeyState()
MantraHK
Posts: 6
Joined: 09 Mar 2024, 00:48

Re: How to check to see if I am holding down the right mouse button?

07 Apr 2024, 16:39

mikeyww wrote:
07 Apr 2024, 06:39

Code: Select all

#Requires AutoHotkey v1.1.33.11

RButton::
KeyWait RButton, T3
Switch ErrorLevel GetKeyState("RButton") {
 Case  0: Click R
 Case 10: Click R D
 Default: Click R U
}
SoundBeep 1000 + 500 * GetKeyState("RButton")
Return
Explained: KeyWaitGetKeyState()
Thank you for your fast reply!
It is so close... I find that while I am holding down the rbutton there is no input to the pc while i am waiting for the 3 seconds.
Is there a way to modify this script that it monitors if the button is held down without interrupting the input?

An example scenario this could solve for is in a game the player needs me to hold down the rbutton to run around.
So when the right button is used the immediate response is still needed and if it's been held down for 3 seconds then the script should take over and hold it down until clicked again.
MantraHK
Posts: 6
Joined: 09 Mar 2024, 00:48

Re: How to check to see if I am holding down the right mouse button?

07 Apr 2024, 20:26

mikeyww wrote:
07 Apr 2024, 16:56
You can try the :arrow: tilde hotkey modifier.
I tried the ~,
"~RButton::"

*Solves the issue whereby I can now right click and the system responds immediately
*Breaks the functionality to read that the button is held down for 3 seconds (it never activates)
User avatar
mikeyww
Posts: 27011
Joined: 09 Sep 2014, 18:38

Re: How to check to see if I am holding down the right mouse button?  Topic is solved

07 Apr 2024, 22:00

Code: Select all

#Requires AutoHotkey v1.1.33.11

RButton::
If !GetKeyState("RButton") {  ; Button is up
 Click R D
 ToolTip % "===> PRESSED <==="
 KeyWait RButton, T3
 If ErrorLevel {              ; Held
  SoundBeep 1500
  Return
 }
} Else KeyWait RButton
Click R U
ToolTip
Return
MantraHK
Posts: 6
Joined: 09 Mar 2024, 00:48

Re: How to check to see if I am holding down the right mouse button?

08 Apr 2024, 04:19

mikeyww wrote:
07 Apr 2024, 22:00

Code: Select all

#Requires AutoHotkey v1.1.33.11

RButton::
If !GetKeyState("RButton") {  ; Button is up
 Click R D
 ToolTip % "===> PRESSED <==="
 KeyWait RButton, T3
 If ErrorLevel {              ; Held
  SoundBeep 1500
  Return
 }
} Else KeyWait RButton
Click R U
ToolTip
Return
You are a legend. This version works perfectly. The Tooltip is a nice bonus.
Thank you!

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 52 guests