Macro Inturrupt to re-input Macro

Ask gaming related questions (AHK v1.1 and older)
SoundchaserSalt
Posts: 3
Joined: 16 Feb 2021, 10:53

Macro Inturrupt to re-input Macro

Post by SoundchaserSalt » 16 Feb 2021, 11:03

Hey all!

Wondering if someone could help with this. I am looking for a way to send an interrupt to the macro with the same key that starts it, so that it starts again even if it had not finished its function. Here is the macro:

Code: Select all

XButton2::
{
	Send, {~}
	click, right
	Send, {q}
	Mousemove, 604, 450
	click down right
}
[Mod edit: [code][/code] tags added.]

I'd like to be to cancel the actions at any point in the process and re-submit it with the same XButton2 key on the mouse. This Macro is used for a video game, and the ~ key acts as a 'move' in the game. Should the 'move' miss its target, I'd like to be able to re-do the XButton2 immediately to try again from the beginning, as opposed to waiting for the Macro to complete. Also, I believe I will need to add an additional sleep or click up right at the end to only make the mouse home last 1.5 seconds.

Edit - This is not a loop either. The macro itself should only last 2 seconds or so at most and then be complete and ready to use again in the next few minutes (or potentially right away if the move misses and the RButton2 needs to be pressed again). I only use this Macro a few times over the course of an hour.

Please let me know if additional information is needed, thank you!
SoundchaserSalt
Posts: 3
Joined: 16 Feb 2021, 10:53

Re: Macro Inturrupt to re-input Macro

Post by SoundchaserSalt » 16 Feb 2021, 14:53

I'm wondering if an 'if' statement can be implemented in the script to end the script and allow the input to be used again right away. This 'if' statement would ideally be the same hotkey (XButton2) or potentially another key, like XButton1. So if XButton1 is pressed during the process of the macro shown above, then the macro would stop and allow XButton2 to be pressed again to start from the beginning.
User avatar
mikeyww
Posts: 27049
Joined: 09 Sep 2014, 18:38

Re: Macro Inturrupt to re-input Macro

Post by mikeyww » 16 Feb 2021, 19:46

Code: Select all

#MaxThreadsPerHotkey 2
XButton2::
go := True
If go
 Send ~
If go
 Click, right
If go
 Send q
If go
 MouseMove, 604, 450
If go
 Click, down, right
go := False
Return
SoundchaserSalt
Posts: 3
Joined: 16 Feb 2021, 10:53

Re: Macro Inturrupt to re-input Macro

Post by SoundchaserSalt » 17 Feb 2021, 10:36

mikeyww wrote:
16 Feb 2021, 19:46

Code: Select all

#MaxThreadsPerHotkey 2
XButton2::
go := True
If go
 Send ~
If go
 Click, right
If go
 Send q
If go
 MouseMove, 604, 450
If go
 Click, down, right
go := False
Return
Thank you for this, truly appreciate it!
I ran the macro this morning and it functions much better than mine. I read up on the #MaxThreadsPerHotkey function and if I understand it correctly it allows for the user to re-submit the macro at any time while it is already running as opposed to it needing to finish before being started again, or something similar.

For the usage of the macro, in testing, I found that it does allow me to re-submit the macro but when the 'second' XButton2 is clicked and finishes it's cycle, the first one then catches up and completes as well. I'm not sure of the order, whether it is #1 or #2 finishing, but it seems as though they are stacked. This creates problems in the game engine, im not sure if there is a way around it.

The only way I can think of is a method for stopping the macro entirely and re-submitting it so that only one instance is running at a time.

In hopes to shed light on what it does, let us say I (the user) click XButton2 to initiate the macro while hovering the mouse over another player. The actions in the macro will use specific abilities to eliminate the enemy. If were to miss hovering on top of the other player and click XButton2, the macro will still take place and I will be stuck using these abilities at nothing, no target. It would be ideal to be able to re-submit the XButton2 after correcting the cursor positioning to on top of the enemy.

If there a function that allows the macro to be canceled and re-sent without having the stacking effect that I am seeing with #MaxThreadsPerHotkey?

Thank you again for your help!
User avatar
mikeyww
Posts: 27049
Joined: 09 Sep 2014, 18:38

Re: Macro Inturrupt to re-input Macro

Post by mikeyww » 17 Feb 2021, 11:38

Actually, I did not see that problem in my testing. The following is a demo. I pressed XButton1 a second time half-way during the sequence.

Code: Select all

#MaxThreadsPerHotkey 2
XButton1::
SetKeyDelay, 300
go := True
If go
 Send ~
If go
 Send q
If go
 Send R
If go
 Send 2
go := False
Return
Output:
~q~qR2

I think what happens:
1. Go=True. Routine starts to run.
2. Second press switches to new thread. Go=True. Routine then starts from beginning & completes, setting Go=False.
3. First thread resumes: at that point, Go=False, so the remaining commands are not executed.

This seems like what you want, but you report something different; I am not sure why you are having a different experience.

I'm not sure of a better method. Some on the forum might know one. Possibly AutoHotkey_H could handle this more effectively. Reload is always an option, too.
Post Reply

Return to “Gaming Help (v1)”