New to AHK and stuck Topic is solved

Get help with using AutoHotkey and its commands and hotkeys
AgentRedCode
Posts: 4
Joined: 14 Jul 2018, 17:17

New to AHK and stuck

14 Jul 2018, 17:33

I've been trying to get this script to work but I can't seem to get it just right. I'm trying to get a macro that can toggle on and off. For example, say I want to press crtl+c whenever I press c (which i can do) but I also want one of my function keys to toggle the script on and off, I'm very new to coding and honestly have no idea how to do this. I feel like this is super simple but I'm just very clueless
AgentRedCode
Posts: 4
Joined: 14 Jul 2018, 17:17

Re: New to AHK and stuck

14 Jul 2018, 17:36

If it helps, the actual keys i want to press is Mouse 4 to activate crtl+e
MannyKSoSo
Posts: 426
Joined: 28 Apr 2018, 21:59

Re: New to AHK and stuck

14 Jul 2018, 17:41

So what you are looking for is something like this?

Code: Select all

F7::
Toggle := !Toggle
while (Toggle) {
If not Toggle
		break
;rest of code
}
Return
The toggle can be done using Toggle := !Toggle which switches between 2 numbers (basically a yes and a no). And to turn it off you put a break in that checks when its completed and the toggle has changed to a no.
Also not that the toggle has to be noted before the loop starts otherwise it will break.
AgentRedCode
Posts: 4
Joined: 14 Jul 2018, 17:17

Re: New to AHK and stuck

14 Jul 2018, 17:50

MannyKSoSo wrote:So what you are looking for is something like this?

Code: Select all

F7::
Toggle := !Toggle
while (Toggle) {
If not Toggle
		break
;rest of code
}
Return
The toggle can be done using Toggle := !Toggle which switches between 2 numbers (basically a yes and a no). And to turn it off you put a break in that checks when its completed and the toggle has changed to a no.
Also not that the toggle has to be noted before the loop starts otherwise it will break.
Im still a little bit confused, just that, how would I add my macro to this.
I still want an action to be played only when i press a certain key and i just don't know how to do that while having a toggle along side.
MannyKSoSo
Posts: 426
Joined: 28 Apr 2018, 21:59

Re: New to AHK and stuck

14 Jul 2018, 17:58

So F7 activates the hot key. You can change it to any button using the ones from this list https://autohotkey.com/docs/KeyList.htm
But that depends on the type of toggle you are looking for. If you are looking for something that can Suspend the script so your button doesn't do the command you can read this https://autohotkey.com/docs/commands/Suspend.htm (specifically the 1st example)
Mouse button 4 is specific to

Code: Select all

XButton1
and you can set it to play once by doing this

Code: Select all

XButton1:: Send ^{e}
AgentRedCode
Posts: 4
Joined: 14 Jul 2018, 17:17

Re: New to AHK and stuck  Topic is solved

14 Jul 2018, 18:08

Ok so I figured it out (no thanks to MannyKSoSo)

I looked at the suspend code and came up with

Code: Select all

F1::Suspend

XButton1:: Send ^{e}
Return 

Return
And yeah i was correct, it was a lot simpler than i thought.
Qysh
Posts: 143
Joined: 24 Apr 2018, 09:16

Re: New to AHK and stuck

14 Jul 2018, 18:09

F7 to toggle the "c" hotkey

Code: Select all

F7::Toggle := !Toggle
#if Toggle
C::MsgBox, hi!

Return to “Ask For Help”

Who is online

Users browsing this forum: Google [Bot] and 230 guests