Page 1 of 1

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

Posted: 07 Apr 2024, 02:27
by MantraHK
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!]

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

Posted: 07 Apr 2024, 06:39
by mikeyww

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()

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

Posted: 07 Apr 2024, 16:39
by MantraHK
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.

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

Posted: 07 Apr 2024, 16:56
by mikeyww
You can try the :arrow: tilde hotkey modifier.

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

Posted: 07 Apr 2024, 20:26
by MantraHK
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)

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

Posted: 07 Apr 2024, 22:00
by mikeyww

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

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

Posted: 08 Apr 2024, 04:19
by MantraHK
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!