Pixelsearch with click on multiple applications simultaneously

Get help with using AutoHotkey and its commands and hotkeys
jvlz
Posts: 3
Joined: 09 Aug 2020, 00:22

Pixelsearch with click on multiple applications simultaneously

09 Aug 2020, 00:27

Hi!

I'm running a script that does a pixelsearch and clicks on the found pixel, it also sends some keyboard inputs to the application.
But I would like to do the same thing for multiple applications running simultaneously. How would I proceed to make sure every script sends the input and does the pixelsearch on its designed application? Also, the mouse click would work if I'm running, lets say, 10 different scripts and applications?

Thanks!
doubledave22
Posts: 42
Joined: 08 Jun 2019, 17:36

Re: Pixelsearch with click on multiple applications simultaneously

09 Aug 2020, 07:40

Why are you running so many scripts to do the same thing? If you combine the code into one script you can make sure to target each program individually.

From help file:

Code: Select all

; Example #2: This will visit all windows on the entire system and display info about each of them:
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinActivate, ahk_id %this_id%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
    IfMsgBox, NO, break
}
If you know the exact name of each application simply WinActivate it and send your clicks and other commands to the window before moving on. You could just set a timer to do this rather than run a million different scripts.
jvlz
Posts: 3
Joined: 09 Aug 2020, 00:22

Re: Pixelsearch with click on multiple applications simultaneously

09 Aug 2020, 12:10

doubledave22 wrote:
09 Aug 2020, 07:40
Why are you running so many scripts to do the same thing? If you combine the code into one script you can make sure to target each program individually.

From help file:

Code: Select all

; Example #2: This will visit all windows on the entire system and display info about each of them:
WinGet, id, list,,, Program Manager
Loop, %id%
{
    this_id := id%A_Index%
    WinActivate, ahk_id %this_id%
    WinGetClass, this_class, ahk_id %this_id%
    WinGetTitle, this_title, ahk_id %this_id%
    MsgBox, 4, , Visiting All Windows`n%a_index% of %id%`nahk_id %this_id%`nahk_class %this_class%`n%this_title%`n`nContinue?
    IfMsgBox, NO, break
}
If you know the exact name of each application simply WinActivate it and send your clicks and other commands to the window before moving on. You could just set a timer to do this rather than run a million different scripts.

But with a timer or winactivate there will be a big delay between the first and last application, right?
I would like to run it simultaneously. Lets say I have 4 windows, If I run a loop that takes 3 seconds each, It would take need to run through the first 3 applications and then run on the last one.
What I'm trying to do is run the pixelsearch every 3 seconds on each window, and send a mouse click and a key if the pixel is found. But I don't think that I can make it work with a loop.
doubledave22
Posts: 42
Joined: 08 Jun 2019, 17:36

Re: Pixelsearch with click on multiple applications simultaneously

09 Aug 2020, 12:44

Which is your priority, speed or reliability? You can try setting up multiple timers although I'm not sure how they'd all interact since ahk is single threaded, someone else would have to help you there. What I am currently learning is the gdip library and all of its functions. You could do the pixel searching without activating each window and at least certain windows you may be able to send/control click without activating as well.

edit: if you had multiple timers they wouldn't have to wait the 3s pause of the other timer. Also consider running the timer something like Settimer, YourLabel, 3000 instead of a quick timer with a built in sleep.

The standard pixelsearch and winactivate method should be pretty fast overall though (worth a shot?) but I am not sure how long the rest of what you are doing for each window is.
jvlz
Posts: 3
Joined: 09 Aug 2020, 00:22

Re: Pixelsearch with click on multiple applications simultaneously

09 Aug 2020, 12:48

doubledave22 wrote:
09 Aug 2020, 12:44
Which is your priority, speed or reliability? You can try setting up multiple timers although I'm not sure how they'd all interact since ahk is single threaded, someone else would have to help you there. What I am currently learning is the gdip library and all of its functions. You could do the pixel searching without activating each window and at least certain windows you may be able to send/control click without activating as well.

edit: if you had multiple timers they wouldn't have to wait the 3s pause of the other timer. Also consider running the timer something like Settimer, YourLabel, 3000 instead of a quick timer with a built in sleep.

The standard pixelsearch and winactivate method should be pretty fast overall though (worth a shot?) but I am not sure how long the rest of what you are doing for each window is.
Huh, what about multiple scripts and assign each one to its own window? Is it possible?
doubledave22
Posts: 42
Joined: 08 Jun 2019, 17:36

Re: Pixelsearch with click on multiple applications simultaneously

09 Aug 2020, 13:13

Well the system only has one cursor and can only activate one window at a time so I don't really think that's what you are trying to accomplish. The scripts will steal focus away from each other. Putting it all into one script will help you organize everything.

Code: Select all

settimer, Check_Apps, 3000
return


Check_Apps:

Winactivate, [APPLICATION WINDOW TITLE1] ; activate the application for pixel search to work properly

pixelsearch, OutX, OutY, x1, y1, x2, y2, SomeColor ; determine the right spot to look
if !ErrorLevel ; returns 0 if found
{
;do some stuff
}

Winactivate, [APPLICATION WINDOW TITLE2] ; activate the application for pixel search to work properly

pixelsearch, OutX, OutY, x1, y1, x2, y2, SomeColor ; determine the right spot to look
if !ErrorLevel ; returns 0 if found
{
;do some stuff
}

Winactivate, [APPLICATION WINDOW TITLE3] ; activate the application for pixel search to work properly

pixelsearch, OutX, OutY, x1, y1, x2, y2, SomeColor ; determine the right spot to look
if !ErrorLevel ; returns 0 if found
{
;do some stuff
}

Winactivate, APPLICATION WINDOW TITLE4 ; activate the application for pixel search to work properly

pixelsearch, OutX, OutY, x1, y1, x2, y2, SomeColor ; determine the right spot to look
if !ErrorLevel ; returns 0 if found
{
;do some stuff
}

return

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Dario91, Google [Bot], nichatr, sebbulon, TAC109 and 33 guests