Help with GetKeyState

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
CorruptingNostalgia
Posts: 10
Joined: 17 Apr 2020, 08:44

Help with GetKeyState

20 Apr 2020, 14:16

whilst i was making a script, i came to realise that GetKeyState did not obey the pause function. Could somebody please help make a script which clicks a lot of time when you hold the left button down which can also be paused, preferably with the pause function.
This is my script as of now:
Pause,on
Lbutton::
while (GetKeyState("Lbutton", "P"))
{
Send {Click}
Sleep, 1
}
`::Pause,Toggle
Many Thanks.
User avatar
boiler
Posts: 16925
Joined: 21 Dec 2014, 02:44

Re: Help with GetKeyState

20 Apr 2020, 15:08

Instead of using Pause, I would use a variable that it checks. When you use Pause, it has to do with the current thread, and hotkeys launching new threads can confuse the issue. Try this:

Code: Select all

Lbutton::
while (GetKeyState("Lbutton", "P"))
{
	if Toggle
	{
		Send {Click}
		Sleep, 1
	}
}
return

`::
	Toggle := !Toggle
	ToolTip, % Toggle ? "ON" : "OFF"
	SetTimer, ToolTipOff, -1000
return

ToolTipOff:
	ToolTip
return

Esc::ExitApp
CorruptingNostalgia
Posts: 10
Joined: 17 Apr 2020, 08:44

Re: Help with GetKeyState

21 Apr 2020, 07:00

this code is really great however when i turn it off it doesn't allow me to press anything. You should try the script to see what i mean

Thanks tho
Aceful
Posts: 6
Joined: 21 Apr 2020, 08:10

Re: Help with GetKeyState

21 Apr 2020, 08:43

I would probably use Hotkey for this.
That way you can turn it on/off without having to remap LButton easily.

Code: Select all

#Persistent
F1::
Toggle:=!Toggle
Hotkey, LButton, LBDown, % Toggle ? "On":"Off"
Return

LBDown:
while (GetKeyState("Lbutton", "P"))
{
	Send {Click}
	Sleep, 1
}
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: AHK_user and 242 guests