Trouble setting up a toggleable macro.

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Skai13
Posts: 4
Joined: 14 Jun 2021, 15:47

Trouble setting up a toggleable macro.

14 Jun 2021, 16:12

This is the first time I've tried creating my own hotkey script and I'm having a bit of trouble.

I'm trying to set up a macro where I can press F5 to activate/deactivate a toggle which would hold down PgUp for the duration of the toggle, while pressing Enter a few times per second.

I've looked online and experimented with a few different Loops, Timers, and Toggles I saw, but none of them have delivered the desired result to far. Most of my attempts have resulted in either a macro that does not start, or repeats until I close AHK. Here's the version I currently have up, though I've tried with multiple others at this point and am ideally looking for a Toggle rather than a loop on a timer. My understanding of this is when I press F5 it would start a 15 second timer where PgUp would be held down for the duration, while Enter is pressed 5 times per second. Can someone please walk me through what I'm doing wrong here and how to set up the Toggle correctly?

Code: Select all

F5:: 
Settimer, Loopme
Loopme:
Loop, 15000
{
	Send, {Enter down}
	Sleep 20
	Send, {Enter up}
	Sleep, 200
        Send, {PgUp down}
}
[Mod edit: [code][/code] tags added.]
Last edited by Skai13 on 14 Jun 2021, 17:36, edited 1 time in total.
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Trouble setting up a toggleable macro.

14 Jun 2021, 16:57

Here is one example.

Code: Select all

F5::
If on := !on {
 Send {PgDn down}
 SetTimer, Go, 200
 SoundBeep, 1500
} Else {
 SetTimer, Go, Off
 Send {PgUp up}
 SoundBeep, 1000
}
Return
Go:
Send {Enter}
Return
Skai13
Posts: 4
Joined: 14 Jun 2021, 15:47

Re: Trouble setting up a toggleable macro.

14 Jun 2021, 17:25

By changing line 3 of the one you sent to include PgUp, I was able to get it to perform the first half of the function correctly. It still does not seem to be pressing Enter at any sort of repeated interval.
Skai13
Posts: 4
Joined: 14 Jun 2021, 15:47

Re: Trouble setting up a toggleable macro.

14 Jun 2021, 17:58

This makes it run through the desired function once correctly, I just need it to repeat itself while the toggle is active.

Code: Select all

F5::
If on := !on {
SetTimer, Go, 200
Send {Enter down}
 SoundBeep, 1500
} Else {
 SetTimer, Go, Off
 Send {Enter up}
 SoundBeep, 1000
}
Return
Go:
Send {PgUp down}
Return
[Mod edit: [code][/code] tags added.]
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Trouble setting up a toggleable macro.

14 Jun 2021, 19:59

Perhaps:

Code: Select all

#MaxThreadsPerHotkey 2
F5::
on := !on
While on {
 Send {Enter down}
 Loop, 75 {
  Send {PgUp}
  Sleep, 200 * on
 } Until !on
 Send {Enter up}
}
Send {Enter up}
Return
Skai13
Posts: 4
Joined: 14 Jun 2021, 15:47

Re: Trouble setting up a toggleable macro.

14 Jun 2021, 22:00

It seems this one is not achieving the desired result either. Looking through this script, it should have worked, but the rapid PgUp presses aren't registering the way I need them to. Is there some sort of complication getting something like this to work that I am not aware of? It sounds simple when I think about it, but not familiar enough with these sort of scrips to work it out.

All I need for it to do is:
1. When I press F5, turn the script on/off.
2. Hold down PgUp awhile the script is turned on.
3. Press Enter every .2 seconds until I turn the script off.
4. When I turn the script off, release PgUp and Enter.

When I perform these key combinations manually, they function as I need, so I know the result is possible; I just don't know where the barrier is.
User avatar
mikeyww
Posts: 26849
Joined: 09 Sep 2014, 18:38

Re: Trouble setting up a toggleable macro.

15 Jun 2021, 05:56

Try this in Notepad. If it works there, try it in your target program.

Code: Select all

F5::
If on := !on {
 Send {PgUp down}
 SetTimer, Go, 200
} Else {
 SetTimer, Go, Off
 Send {PgUp up}
}
Return
Go:
Send {Enter}
Return

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: OrangeCat and 244 guests