Any way to "fake" a winactivate?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
sachalamp
Posts: 21
Joined: 08 Apr 2024, 12:47

Any way to "fake" a winactivate?

23 May 2024, 07:23

I am running multiple instances of bluestacks and i made my script activate and circle through each window, one at a time and run various scripts in each. I put in a lot of effort so far and it's working surprisingly well however i figured i want to do other things while this is running.

I replaced clicks with control clicks but the fundamental problem is the way the script is designed to run - activating each window and then checking which window is active and updating some variables depending on the window.

So controlsends won't help if i can't change the way i design my script and i have no idea how to do it and if that's even possible.


[Mod action: Moved topic from “Ask for Help (v1)” after it was revealed OP is using PMC, not asking for help with an AHK script.]
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Any way to "fake" a winactivate?

23 May 2024, 10:46

Why is your script basing things on which window is active if you're using ControlSends? Just cycle through the windows and act on each without activating them. Not sure why you are saying you can't change the design of your script. Change it so it works the way you want.
sachalamp
Posts: 21
Joined: 08 Apr 2024, 12:47

Re: Any way to "fake" a winactivate?

24 May 2024, 01:33

boiler wrote:
23 May 2024, 10:46
Why is your script basing things on which window is active if you're using ControlSends? Just cycle through the windows and act on each without activating them. Not sure why you are saying you can't change the design of your script. Change it so it works the way you want.
I am new to ahk and i don't quite understand how the window thing works despite reading the documentation. When i started the thing i didn't even consider i can use contolsends and now i regret picking this approach considering i created a lot of actions in this manner. I updated some of the script with controlsends then i realized it's pointless since the window has to be active and i will inevitably activate other windows with my mouse.

I work in Pulover Macro and my script needs to infinitely cycle through some actions which are generally the same for the 4 instances i am using, however i also need to trigger some only after X hours passed. For this i export the a_now to a text file and use an envsub function to compare time passed.

The first picture is the infinite loop that cycles all the windows and actions
Image

The second one is showing how based on what window is active it will check time passed and then break if not enough time has passed. If it can execute the action for the specific window, it will, and then export a_now to a text file

Image
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Any way to "fake" a winactivate?

24 May 2024, 04:40

sachalamp wrote: I updated some of the script with controlsends then i realized it's pointless since the window has to be active and i will inevitably activate other windows with my mouse.
How did you determine the window has to be active? And if so, no big deal. Just use regular Send. You are making this sound way more complicated than it should be.

sachalamp wrote: I work in Pulover Macro…
Then I will not be helping you, and this is not the right section of the forum to ask for help with that tool. Most AHK users do not use PMC and would not be providing help with it. I am moving this thread to the PMC section.
sachalamp
Posts: 21
Joined: 08 Apr 2024, 12:47

Re: Any way to "fake" a winactivate?

24 May 2024, 07:02

boiler wrote:
24 May 2024, 04:40
sachalamp wrote: I updated some of the script with controlsends then i realized it's pointless since the window has to be active and i will inevitably activate other windows with my mouse.
How did you determine the window has to be active? And if so, no big deal. Just use regular Send. You are making this sound way more complicated than it should be.

sachalamp wrote: I work in Pulover Macro…
Then I will not be helping you, and this is not the right section of the forum to ask for help with that tool. Most AHK users do not use PMC and would not be providing help with it. I am moving this thread to the PMC section.
As shown in the second picture, some actions are executed and some variables are updated based on what windows is active.

I didn't post it here for Pulover help, i posted the picture to give a general idea of how the script looks like, otherwise those would be hundreds of lines of code. Pulover is very good on providing a top-down view of the script.

The code does work, i was looking for other syntax/logic, if that even exists. I might as well do it in regular ahk, i don't know what syntax/logic to use.
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Any way to "fake" a winactivate?

24 May 2024, 07:49

If you’re going to produce native AHK code and are looking for help with that, we can move the thread back to the main part of the forum. If so, post some AHK code that you have questions about. Your first post provides no specifics, and your second post is not AHK code.
sachalamp
Posts: 21
Joined: 08 Apr 2024, 12:47

Re: Any way to "fake" a winactivate?

24 May 2024, 10:09

boiler wrote:
24 May 2024, 07:49
If you’re going to produce native AHK code and are looking for help with that, we can move the thread back to the main part of the forum. If so, post some AHK code that you have questions about. Your first post provides no specifics, and your second post is not AHK code.
This goes up to winactivate d4 in an infinite loop

Code: Select all

WinActivate, a1  ; a1
Sleep, 333
Gosub, load_game
Gosub, energy  ; energy
/*
Gosub, energy_can  ; energy CAN
*/
Gosub, launch_decide  ; LAUNCH
Gosub, heal_decide  ; heal
Gosub, help  ; help
/*
Gosub, getaway  ; getaway
*/
Gosub, gather_production  ; production
Gosub, shakedown
Gosub, clan_pts  ; clan pts
/*
Gosub, garden_pick  ; garden pick 
Gosub, shield_buff  ; shield buff
*/
Sleep, 1000
WinActivate, b2  ; b2
Sleep, 333
Gosub, load_game
Gosub, energy  ; energy
Gosub, launch_decide  ; LAUNCH
Gosub, heal_decide  ; heal
Gosub, help  ; help
/*
Gosub, getaway  ; getaway
*/
Gosub, gather_production  ; production
Gosub, shakedown
Gosub, clan_pts  ; clan pts
This is one of the many gosubs that is launched in each window. This first part checks the window active and decides whether to continue or not.

Code: Select all

IfWinActive, a1
{
	FileRead, last_clanpts_a1, D:\mafia\variables\last_clanpts_a1.txt
	Sleep, 10
	z := checkduration(last_clanpts_a1, 15000)
	If (z != 1)
	{
		Break
		Sleep, 10
	}
}
IfWinActive, b2
{
	FileRead, last_clanpts_b2, D:\mafia\variables\last_clanpts_b2.txt
	Sleep, 10
	z := checkduration(last_clanpts_b2, 15000)
	If (z != 1)
	{
		Break
		Sleep, 10
	}
Then the code for the window

Code: Select all

Sleep, 1000
CoordMode, Pixel, Window
ImageSearch, FoundX, FoundY, 200, 421, 241, 456, *30 C:\Users\UnrealOne\AppData\Roaming\MacroCreator\Screenshots\Screen_20240506124733.png
If ErrorLevel = 0
	Click, %FoundX%, %FoundY% Left, 1
If ErrorLevel
	Break
Sleep, 1000
Sleep, 300
CoordMode, Pixel, Window
PixelSearch, FoundX, FoundY, 151, 313, 205, 321, 0xBB966E, 10, Fast RGB
If ErrorLevel = 0
	Click, %FoundX%, %FoundY% Left, 1
Sleep, 1000
If (ErrorLevel)
{
	Send, {Escape}
	Sleep, 1000
	Break
	Sleep, 1000
}
Sleep, 300
Loop
{
	CoordMode, Pixel, Window
	PixelSearch, FoundX, FoundY, 112, 123, 151, 138, 0x5E1200, 15, Fast RGB
	If ErrorLevel = 0
		Click, %FoundX%, %FoundY% Left, 1
	Sleep, 1000
}
Until ErrorLevel = 0
Loop
{
	Sleep, 1200
	CoordMode, Pixel, Window
	PixelSearch, FoundX, FoundY, 101, 248, 145, 258, 0x913434, 20, Fast RGB  ; check daca poate
	Sleep, 1200
	If (ErrorLevel)
	{
		CoordMode, Pixel, Window
		PixelSearch, FoundX, FoundY, 138, 301, 166, 315, 0xB37906, 0, Fast RGB
		If ErrorLevel = 0
			Click, %FoundX%, %FoundY% Left, 1  ; contrib 3
		Sleep, 1000
		If (ErrorLevel)
		{
			CoordMode, Pixel, Window
			PixelSearch, FoundX, FoundY, 28, 306, 55, 316, 0xAE7C09, 0, Fast RGB
			If ErrorLevel = 0
				Click, %FoundX%, %FoundY% Left, 1  ; contrib 2
			Sleep, 1000
			If (ErrorLevel)
			{
				CoordMode, Pixel, Window
				PixelSearch, FoundX, FoundY, 83, 270, 99, 280, 0x5C861A, 0, Fast RGB
				If ErrorLevel = 0
					Click, %FoundX%, %FoundY% Left, 1  ; contrib 1
				Sleep, 1000
			}
		}
	}
	Else
	{
		Send, {Escape}
		Sleep, 1000
		Send, {Escape}
		Sleep, 1000
		Send, {Escape}
		Sleep, 1000
		Break
		Sleep, 1000
	}
}
Then IF the code was allowed to run based on the first part that checks window active, it will update some time values

Code: Select all

IfWinActive, a1
{
	last_clanpts_a1 := a_now
	FileDelete, D:\mafia\variables\last_clanpts_a1.txt
	Sleep, 10
	FileAppend, %last_clanpts_a1%, D:\mafia\variables\last_clanpts_a1.txt
	Sleep, 10
	Break
	Sleep, 1000
}
IfWinActive, b2
{
	last_clanpts_b2 := a_now
	FileDelete, D:\mafia\variables\last_clanpts_b2.txt
	Sleep, 10
	FileAppend, %last_clanpts_b2%, D:\mafia\variables\last_clanpts_b2.txt
	Sleep, 10
	Break
	Sleep, 1000
}
As i said in the beginning this code works just fine, i am looking for a solution to run this through ctrlsends and not winactivate as i would like to do other stuff on my pc while this is running
sachalamp
Posts: 21
Joined: 08 Apr 2024, 12:47

Re: Any way to "fake" a winactivate?

27 May 2024, 07:37

boiler wrote:
24 May 2024, 07:49
If you’re going to produce native AHK code and are looking for help with that, we can move the thread back to the main part of the forum. If so, post some AHK code that you have questions about. Your first post provides no specifics, and your second post is not AHK code.
i provided the code 2 days ago
Last edited by gregster on 27 May 2024, 07:59, edited 1 time in total.
Reason: Moved topic to v1 help.
User avatar
boiler
Posts: 17404
Joined: 21 Dec 2014, 02:44

Re: Any way to "fake" a winactivate?

27 May 2024, 12:08

sachalamp wrote: I updated some of the script with controlsends then i realized it's pointless since the window has to be active and i will inevitably activate other windows with my mouse.
I don’t understand what makes you say the window has to be active, but if that’s true and that makes using ControlSend pointless, then I don’t know why you’re asking help with implementing ControlSend. If that’s not really what you mean and ControlSend would work, then post your attempt at using it. Start with a simple script to demonstrate whether it would work on your windows or not. I would think you would also need to use ControlClick.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Rauvagol and 312 guests