How to block a key's native function for only part of the code

Get help with using AutoHotkey and its commands and hotkeys
Darion
Posts: 10
Joined: 24 Jan 2019, 11:11

How to block a key's native function for only part of the code

24 Jan 2019, 14:21

Hello everyone. Here is my example for editing left mouse-clicking, it has two functions:
1. When un-toggled, LButton's function retained, pass all original left-clicks;
2. When toggled, LButton's function retained, unless LButton is held down for more than 1s (spam Space in this case).

Code: Select all

~LButton::
	If (!Toggle)
		return								; Changes nothing when un-toggled
	KeyWait LButton, T1						; When toggled, wait 1s for releasing LButton
	If ErrorLevel							; LButton still held down
		While GetKeyState("LButton", "P"){	; When LButton is held down
			Send, {Space}
			Sleep 100						; Spam Space
		}
	return
However, I found in the case of spaming Space, it also spams LButton as well, which is what I want to block (to only spam Space).

So I wonder is there a specific command for blocking a key's native function, only for the spam Space part of the code?
Or should I do it in some other way? Any help would be appreciated.
Last edited by Darion on 24 Jan 2019, 15:50, edited 4 times in total.
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: How to block a key's native function while using ~ prefix

24 Jan 2019, 14:48

if !toggle send {Click} ;d
also remove ~, add * because you will send click in your code.
Darion
Posts: 10
Joined: 24 Jan 2019, 11:11

Re: How to block a key's native function while using ~ prefix

24 Jan 2019, 15:24

mast4rwang wrote:
24 Jan 2019, 14:48
if !toggle send {Click} ;d
also remove ~, add * because you will send click in your code.
Thanks for the help.
At first I tried not using the ~ prefix and adding Send {Click}, but this would change the output of both single clicks AND holding down clicks into single clicks, which is not what I want.
Is there anyway to write the full click function (with holding down output), instead of just Send {Click}?
mast4rwang
Posts: 141
Joined: 19 Jul 2017, 09:59

Re: How to block a key's native function while using ~ prefix

25 Jan 2019, 10:59

Darion wrote:
24 Jan 2019, 15:24
mast4rwang wrote:
24 Jan 2019, 14:48
if !toggle send {Click} ;d
also remove ~, add * because you will send click in your code.
Thanks for the help.
At first I tried not using the ~ prefix and adding Send {Click}, but this would change the output of both single clicks AND holding down clicks into single clicks, which is not what I want.
Is there anyway to write the full click function (with holding down output), instead of just Send {Click}?
Yeah,

if !toggle
{
send,{LButton Down}
keywait,LButton
send,{LButton Up}
}
Darion
Posts: 10
Joined: 24 Jan 2019, 11:11

Re: How to block a key's native function while using ~ prefix

27 Jan 2019, 18:17

mast4rwang wrote:
24 Jan 2019, 14:48
if !toggle
{
send,{LButton Down}
keywait,LButton
send,{LButton Up}
}
You are the man, thank you!

Meanwhile I also find a solution to block the native function. In my case, add "Click, up" just before the part where Space loop begins.
Not sure how, but it also worked flawlessly. Posting here in case it helps someone.

Code: Select all

~LButton::
	if (!Toggle)
		return
	KeyWait LButton, T0.3
	Click, up
	if ErrorLevel
		while GetKeyState("LButton", "P"){
			Send, {Space}
			Sleep 100
		}
return

Return to “Ask For Help”

Who is online

Users browsing this forum: Albireo, Bing [Bot], Breevz, DMDComposer, IIoPTeP, MannyKSoSo, Odlanir, teadrinker, vsub and 180 guests