Holding down button causing a function

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
s0gy
Posts: 7
Joined: 26 May 2022, 13:57

Holding down button causing a function

Post by s0gy » 27 Jun 2022, 16:03

Is it possible to code a way where when you hold down the left click button an action actively repeats however as soon as left click is let go it stops? Any help is appreciated.

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Holding down button causing a function

Post by mikeyww » 27 Jun 2022, 16:45

Code: Select all

LButton::
While GetKeyState("LButton", "P") {
 Send x
 Sleep, 20
}
Return

s0gy
Posts: 7
Joined: 26 May 2022, 13:57

Re: Holding down button causing a function

Post by s0gy » 28 Jun 2022, 17:06

How would I also make this script only work in a certain application? also thanks for the help.


s0gy
Posts: 7
Joined: 26 May 2022, 13:57

Re: Holding down button causing a function

Post by s0gy » 29 Jun 2022, 11:57

Please can you write a demonstration as this doesn't seem to be working, this is my code:

Code: Select all

#IfWinActive ahk_class Notepad

return

LButton::
While GetKeyState("LButton", "P") {
  mouseMove, 0, 100, 10, R
 Sleep, 20
}

Return
[Mod edit: [code][/code] tags added.]

User avatar
mikeyww
Posts: 26883
Joined: 09 Sep 2014, 18:38

Re: Holding down button causing a function

Post by mikeyww » 29 Jun 2022, 12:06

Code: Select all

notepad = ahk_class Notepad
#If WinExist(notepad) && mouseOver(notepad)
LButton::
If !WinActive(notepad)
 WinActivate
Loop {
 MouseMove, 0, 100, 10, R
 Sleep, 20
} Until !GetKeyState("LButton", "P")
Return
#If

mouseOver(winTitle) {
 MouseGetPos,,, hWnd
 Return WinExist(winTitle " ahk_id" hWnd)
}

Post Reply

Return to “Ask for Help (v1)”