Switch numpad with mouseclick

Ask gaming related questions (AHK v1.1 and older)
Eltrago
Posts: 2
Joined: 15 Jan 2018, 13:45

Switch numpad with mouseclick

15 Jan 2018, 14:00

Hi,

I just found out about AutoHotkey and I'd like to make a script for a game.
I want to start the script when I press something like ctrl+b, and when I click the left mouse button I want it to switch to numpad 3, when I click again I want it to go back to numpad 2, when I click again back to numpad 3, etc.. when I press ctrl+n I want the script to end.
tl;dr: want to switch numpad when I press the left mouse button

I currently have this:

Code: Select all

^b::
loop
{
LButton::
	send, Numpad3
LButton::
	send, Numpad2
}
^n::ExitApp
But this doesn't work and I dont know how to make it toggle between numpad 2 & 3..

Thanks,
Siebe
User avatar
Spawnova
Posts: 554
Joined: 08 Jul 2015, 00:12
Contact:

Re: Switch numpad with mouseclick

15 Jan 2018, 18:15

Code: Select all

numpadToggle := 2
running := false

#if running
	lbutton::
	send {numpad%numpadToggle%}
	numpadToggle := (numpadToggle = 2 ? 3 : 2)
	return
#if

^b::running := !running
^n::exitapp
Here's the same code but with comments, explaining what things do.

Code: Select all

numpadToggle := 2 ;variable numpadToggle has a value of 2
running := false ;boolean false/true can also be 0/1, note running = false is NOT the same thing, without ":=" it is considered string

#if running ;hotkey conditional, below hotkeys only work if it's true, in this case only if running = true
lbutton::
;use brackets because we are not sending string, but a special key, numpad2/numpad3
send {numpad%numpadToggle%} ;when a variable is enclosed in percent signs it tells the script it is a variable and to use the value of that variable, and not literal "numpadToggle"
numpadToggle := (numpadToggle = 2 ? 3 : 2) ;(condition=true ? ifYes : ifNo)
/*
the above is a condensed if statement, below is a normal if statement, you can see it saves a lot of space
if (numpadToggle = 2)
	numpadToggle := 3
else
	numpadToggle := 2
*/
return
#if ;hotkey condition removed, all hotkeys below work

^b::running := !running  ;toggles running, true>false>true>false etc.
^n::exitapp ;closes the program down

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Google [Bot], jameswrightesq and 108 guests