how to make middle mouse button alternate between inputing three times and once per click

Ask gaming related questions
User avatar
Theleifblower
Posts: 12
Joined: 16 May 2024, 16:12

how to make middle mouse button alternate between inputing three times and once per click

16 May 2024, 20:46

"MouseClick WhichButton, X, Y, ClickCount, Speed, DownOrUp, Relative"

i see that i can use this for the actual clicking part (potentially)

mouseclick "mbutton,,,3"

mouseclick "mbutton"

these would be the two outputs i want to alternate assuming i got the format right

with the hotkey also being the middle mouse button

*mbutton::

as for the logic behind switching the outputs each time the hotkey is pressed im very unsure and could use help. some parts of what i already have may also be wrong
User avatar
Noitalommi_2
Posts: 316
Joined: 16 Aug 2023, 10:58

Re: how to make middle mouse button alternate between inputing three times and once per click

16 May 2024, 21:49

Hi.

Please try this.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance


SendMode "Event"
SetMouseDelay 100 ; delay after each click in ms
*MButton:: {

	static toggle := 1

	if toggle := !toggle
		Click
	else Click(,, 3)
}
Edit: Different approach but same result.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance

*MButton:: {

	static toggle := 1
	, Delay := 100

	if toggle := !toggle {
		Send("{LButton down}"), Sleep(Delay), Send("{LButton up}")
	}
	else {

		Loop 3
			Send("{LButton down}"), Sleep(Delay), Send("{LButton up}")
	}
}
smith2
Posts: 6
Joined: 06 May 2024, 00:14
Contact:

Re: how to make middle mouse button alternate between inputing three times and once per click

16 May 2024, 23:11

After reading your post I will recommend you to use this method if it work like
"mouseclick" with "mbutton" triggers a middle mouse click.

Toggle click behavior:

Use a variable (ClickType) to store "normal" or "alternative" click.
In your hotkey script:
Perform the click based on ClickType.
Toggle ClickType after each click (e.g., ClickType := ClickType == "normal" ? "alternative" : "normal").
Alternative click example:

Define your alternative action (e.g., send a keystroke).
In the hotkey script, if ClickType is "alternative", send the defined action instead of a click.
User avatar
Theleifblower
Posts: 12
Joined: 16 May 2024, 16:12

Re: how to make middle mouse button alternate between inputing three times and once per click

19 May 2024, 20:53

Noitalommi_2 wrote:
16 May 2024, 21:49
Hi.

Please try this.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance


SendMode "Event"
SetMouseDelay 100 ; delay after each click in ms
*MButton:: {

	static toggle := 1

	if toggle := !toggle
		Click
	else Click(,, 3)
}
Edit: Different approach but same result.

Code: Select all

#Requires AutoHotkey 2.0
#SingleInstance

*MButton:: {

	static toggle := 1
	, Delay := 100

	if toggle := !toggle {
		Send("{LButton down}"), Sleep(Delay), Send("{LButton up}")
	}
	else {

		Loop 3
			Send("{LButton down}"), Sleep(Delay), Send("{LButton up}")
	}
}

this is the code im currently using

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2

SendMode "Event"
SetMouseDelay(100)

*MButton:: {
	
	static toggle := 1

	if toggle := !toggle
		send "{Click m }"
	else send "{Click 3 m }"
	
	
}
it does exactly what i want, but the issue is if i click the hotkey while the script is running that input will get through to my game, is there a way i can disable that mouse button while this script is running so that only the script can give an input to the game, and it only gives said input when i press the button

[Mod edit: Added [code][/code] tags. Please use them yourself when posting code!]
gregster
Posts: 9109
Joined: 30 Sep 2013, 06:48

Re: how to make middle mouse button alternate between inputing three times and once per click

19 May 2024, 20:58

@Theleifblower, please use code tags when posting code! Thank you.

ctags.png
ctags.png (14.18 KiB) Viewed 386 times
User avatar
Theleifblower
Posts: 12
Joined: 16 May 2024, 16:12

Re: how to make middle mouse button alternate between inputing three times and once per click

19 May 2024, 22:47

i managed to figure it out myself

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2

SendMode "event"
blockinput "mouse"

*MButton:: {

	static toggle := 1

	if toggle := !toggle
		Click "Middle"
	else Click "3 Middle"
	
}
User avatar
Theleifblower
Posts: 12
Joined: 16 May 2024, 16:12

Re: how to make middle mouse button alternate between inputing three times and once per click

19 May 2024, 23:38

but then of course its not fully working, i no longer get the issue with keys being registered while the script is running, but if i release a key im holding while the scrip is running it gets stuck down until i press it again, this is not really very ideal at all either, any thoughts on how this can be fixed?

current script:

Code: Select all

#SingleInstance Force
#Requires AutoHotkey v2

SendMode "event"
blockinput "mouse"

*MButton:: {

	static toggle := 1

	if toggle := !toggle
		Click "Middle"
	else Click "3 Middle"
	
}
User avatar
Theleifblower
Posts: 12
Joined: 16 May 2024, 16:12

Re: how to make middle mouse button alternate between inputing three times and once per click

19 May 2024, 23:41

is there any way i can isolate the middle mouse button to be the only key that has its input blocked while the script runs
User avatar
Noitalommi_2
Posts: 316
Joined: 16 Aug 2023, 10:58

Re: how to make middle mouse button alternate between inputing three times and once per click

20 May 2024, 03:16

Theleifblower wrote:
19 May 2024, 23:41
is there any way i can isolate the middle mouse button to be the only key that has its input blocked while the script runs
Try the second script I posted.

Return to “Gaming”

Who is online

Users browsing this forum: No registered users and 8 guests