dealing with multiple scripts

Get help with using AutoHotkey and its commands and hotkeys
nicolo
Posts: 23
Joined: 28 Apr 2016, 04:57

dealing with multiple scripts

28 Apr 2016, 05:32

Hi,

I read there could be problems if several scripts using mouse moves are launched at the same time.

My question is : is it possible that the scripts get queued so that they are executed one by one following the order of launch?

Thanks
User avatar
Flarebrass
Posts: 104
Joined: 20 Nov 2015, 13:13
Location: USA
Contact:

Re: dealing with multiple scripts

28 Apr 2016, 05:45

You're looking for the Critical command. Specify code as in the following:

Code: Select all

Numpad1::
Critical
;uninterruptable code here, will buffer keyboard input and mouse clicks
Critical Off
return
(Note that I can't test my code before posting, so beware of bugs! -Flarebrass Amatzikahni)
nicolo
Posts: 23
Joined: 28 Apr 2016, 04:57

Re: dealing with multiple scripts

28 Apr 2016, 06:54

Thank you!
Do you know if this command is inside 2 .exe macros launched 1 after the other one (given that each exe doesn't need to press any key to execute the macro : https://autohotkey.com/boards/viewtopic ... 941#p83941)
after one test, it seems that the 2 .exe macros still interfere, even with this Critical command inside.
nicolo
Posts: 23
Joined: 28 Apr 2016, 04:57

Re: dealing with multiple scripts

28 Apr 2016, 07:07

by the way, here is the content of each .exe file : exe #♥1 :

; This script was created using Pulover's Macro Creator
; www.macrocreator.com

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1


Macro2:
Critical
Sleep, 516
Click, 936, 466, 0
Sleep, 15
Click, 931, 474, 0
Sleep, 16
Click, 929, 479, 0
Click, 926, 485, 0
Sleep, 15
Click, 918, 505, 0
Sleep, 16
Click, 915, 520, 0
Click, 911, 534, 0
Sleep, 16
Click, 905, 551, 0
Click, 902, 563, 0
Sleep, 15
Click, 898, 577, 0
Sleep, 16
Click, 897, 584, 0
Sleep, 16
Click, 896, 590, 0
Sleep, 15
Click, 896, 593, 0
Sleep, 16
Click, 895, 600, 0
Sleep, 15
Click, 891, 611, 0
Click, 889, 618, 0
Sleep, 16
Click, 884, 632, 0
Sleep, 16
Click, 881, 642, 0
Sleep, 15
Click, 876, 657, 0
Sleep, 16
Click, 874, 669, 0
Sleep, 16
Click, 871, 677, 0
Sleep, 15
Click, 869, 685, 0
Sleep, 16
Click, 867, 690, 0
Sleep, 15
Click, 862, 699, 0
Sleep, 16
Click, 859, 707, 0
Sleep, 16
Click, 853, 716, 0
Sleep, 15
Click, 849, 726, 0
Sleep, 16
Click, 847, 731, 0
Click, 846, 734, 0
Sleep, 16
Click, 841, 743, 0
Sleep, 15
Click, 838, 748, 0
Click, 835, 751, 0
Sleep, 16
Click, 830, 758, 0
Click, 828, 761, 0
Sleep, 31
Click, 822, 765, 0
Click, 820, 767, 0
Click, 816, 769, 0
Sleep, 31
Click, 812, 771, 0
Click, 810, 773, 0
Sleep, 16
Click, 806, 775, 0
Click, 804, 777, 0
Sleep, 16
Click, 803, 779, 0
Click, 800, 780, 0
Sleep, 15
Click, 798, 781, 0
Click, 794, 785, 0
Sleep, 31
Click, 788, 788, 0
Click, 786, 789, 0
Sleep, 16
Click, 784, 790, 0
Click, 782, 791, 0
Sleep, 16
Click, 782, 792, 0
Click, 781, 793, 0
Sleep, 31
Click, 780, 793, 0
Sleep, 47
Click, 780, 794, 0
Sleep, 62
Click, 780, 795, 0
Click, 780, 796, 0
Sleep, 16
Click, 780, 797, 0
Sleep, 16
Click, 780, 798, 0
Sleep, 15
Click, 780, 799, 0
Click, 781, 801, 0
Sleep, 16
Click, 783, 803, 0
Sleep, 15
Click, 784, 804, 0
Click, 785, 807, 0
Click, 787, 809, 0
Sleep, 16
Click, 788, 810, 0
Sleep, 16
Click, 788, 811, 0
Sleep, 31
Click, 789, 811, 0
Sleep, 16
Click, 790, 811, 0
Sleep, 15
Click, 790, 812, 0
Sleep, 16
Click, 791, 812, 0
Sleep, 15
Click, 793, 814, 0
Click, 794, 814, 0
Sleep, 16
Click, 794, 815, 0
Sleep, 16
Click, 796, 816, 0
Sleep, 31
Click, 797, 816, 0
Sleep, 31
Click, 801, 814, 0
Click, 803, 813, 0
Sleep, 31
Click, 803, 812, 0
Sleep, 32
Click, 804, 812, 0
Sleep, 31
Click, 805, 812, 0
Sleep, 78
Click, 806, 812, 0
Sleep, 47
Click, 808, 812, 0
Click, 809, 813, 0
Sleep, 31
Click, 810, 814, 0
Sleep, 219
Click, 811, 813, 0
Sleep, 16
Click, 812, 812, 0
Sleep, 15
Click, 813, 810, 0
Sleep, 16
Click, 814, 808, 0
Sleep, 15
Click, 815, 807, 0
Click, 816, 805, 0
Sleep, 16
Click, 816, 803, 0
Sleep, 16
Click, 818, 801, 0
Sleep, 15
Click, 818, 799, 0
Sleep, 47
Click, 819, 798, 0
Sleep, 63
Click, 819, 796, 0
Sleep, 47
Click, 819, 795, 0
Sleep, 93
Click, 818, 794, 0
Sleep, 32
Click, 818, 793, 0
Sleep, 15
Click, 817, 793, 0
Sleep, 31
Click, 816, 793, 0
Sleep, 32
Click, 816, 792, 0
Sleep, 15
Click, 815, 792, 0
Sleep, 32
Click, 814, 791, 0
Sleep, 62
Click, 813, 791, 0
Sleep, 16
Click, 812, 790, 0
Sleep, 31
Click, 810, 789, 0
Sleep, 16
Click, 809, 789, 0
Sleep, 62
Click, 807, 789, 0
Sleep, 31
Click, 806, 788, 0
Sleep, 47
Click, 805, 788, 0
Sleep, 31
Click, 804, 788, 0
Sleep, 32
Click, 803, 788, 0
Sleep, 31
Click, 802, 788, 0
Sleep, 16
Click, 800, 788, 0
Sleep, 31
Click, 799, 788, 0
Sleep, 15
Click, 798, 788, 0
Sleep, 16
Click, 797, 788, 0
Sleep, 31
Click, 795, 788, 0
Sleep, 125
Click, 794, 788, 0
Sleep, 297
Click, 786, 780 Left, Down
Sleep, 31
Click, 463, 617, 0
Sleep, 32
Click, 463, 617 Left, Up
Sleep, 1031
Click, 471, 609, 0
Sleep, 16
Click, 485, 598, 0
Sleep, 15
Click, 503, 585, 0
Sleep, 16
Click, 516, 572, 0
Sleep, 15
Click, 531, 560, 0
Sleep, 16
Click, 538, 550, 0
Click, 541, 544, 0
Sleep, 31
Click, 546, 524, 0
Sleep, 16
Click, 548, 509, 0
Sleep, 16
Click, 550, 493, 0
Sleep, 15
Click, 554, 483, 0
Sleep, 16
Click, 558, 467, 0
Sleep, 31
Click, 569, 451, 0
Sleep, 16
Click, 582, 431, 0
Sleep, 15
Click, 588, 418, 0
Sleep, 16
Click, 592, 403, 0
Sleep, 16
Click, 595, 388, 0
Sleep, 15
Click, 597, 376, 0
Sleep, 31
Click, 598, 366, 0
Click, 599, 363, 0
Sleep, 16
Click, 599, 357, 0
Sleep, 31
Click, 599, 352, 0
Sleep, 16
Click, 599, 345, 0
Sleep, 16
Click, 599, 340, 0
Sleep, 15
Click, 597, 327, 0
Sleep, 16
Click, 596, 319, 0
Sleep, 31
Click, 595, 315, 0
Sleep, 31
Click, 595, 313, 0
Sleep, 16
Click, 594, 311, 0
Sleep, 31
Click, 593, 309, 0
Sleep, 16
Click, 592, 305, 0
Sleep, 15
Click, 591, 303, 0
Sleep, 16
Click, 591, 302, 0
Sleep, 63
Click, 590, 301, 0
Sleep, 46
Click, 589, 301, 0
Sleep, 16
Click, 587, 299, 0
Sleep, 94
Click, 586, 298, 0
Sleep, 31
Click, 585, 298, 0
Sleep, 219
Click, 585, 297, 0
Critical Off
Return
nicolo
Posts: 23
Joined: 28 Apr 2016, 04:57

Re: dealing with multiple scripts

28 Apr 2016, 07:08

exe #♥2 :

; This script was created using Pulover's Macro Creator
; www.macrocreator.com

#NoEnv
SetWorkingDir %A_ScriptDir%
CoordMode, Mouse, Window
SendMode Input
#SingleInstance Force
SetTitleMatchMode 2
#WinActivateForce
SetControlDelay 1
SetWinDelay 0
SetKeyDelay -1
SetMouseDelay -1
SetBatchLines -1


Macro1:
Critical
Sleep, 333
Sleep, 437
Click, 1596, 233, 0
Sleep, 16
Click, 1617, 244, 0
Sleep, 16
Click, 1635, 254, 0
Sleep, 15
Click, 1662, 272, 0
Click, 1680, 282, 0
Sleep, 16
Click, 1700, 290, 0
Sleep, 16
Click, 1734, 302, 0
Sleep, 15
Click, 1767, 310, 0
Sleep, 16
Click, 1790, 314, 0
Click, 1820, 316, 0
Sleep, 15
Click, 1853, 316, 0
Sleep, 16
Click, 1930, 321, 0
Click, 1960, 321, 0
Sleep, 16
Click, 1990, 321, 0
Click, 2012, 321, 0
Sleep, 15
Click, 2024, 321, 0
Click, 2034, 320, 0
Sleep, 16
Click, 2039, 318, 0
Click, 2043, 315, 0
Sleep, 16
Click, 2045, 312, 0
Sleep, 15
Click, 2050, 303, 0
Click, 2053, 294, 0
Sleep, 16
Click, 2062, 278, 0
Sleep, 15
Click, 2068, 271, 0
Click, 2075, 261, 0
Sleep, 16
Click, 2083, 252, 0
Sleep, 16
Click, 2097, 242, 0
Click, 2102, 237, 0
Sleep, 15
Click, 2107, 233, 0
Sleep, 16
Click, 2107, 231, 0
Click, 2107, 227, 0
Sleep, 16
Click, 2107, 221, 0
Click, 2105, 213, 0
Sleep, 15
Click, 2097, 195, 0
Sleep, 16
Click, 2096, 193, 0
Sleep, 312
Click, 2099, 197, 0
Click, 2104, 200, 0
Sleep, 16
Click, 2106, 202, 0
Click, 2108, 203, 0
Sleep, 125
Click, 2114, 206, 0
Click, 2117, 207, 0
Sleep, 16
Click, 2120, 209, 0
Click, 2123, 211, 0
Sleep, 15
Click, 2129, 216, 0
Click, 2140, 224, 0
Click, 2154, 234, 0
Sleep, 16
Click, 2168, 244, 0
Sleep, 15
Click, 2184, 253, 0
Click, 2209, 268, 0
Sleep, 32
Click, 2225, 275, 0
Sleep, 15
Click, 2236, 282, 0
Click, 2242, 286, 0
Sleep, 16
Click, 2249, 291, 0
Click, 2255, 296, 0
Sleep, 16
Click, 2267, 307, 0
Sleep, 15
Click, 2297, 335, 0
Click, 2312, 350, 0
Sleep, 16
Click, 2321, 360, 0
Sleep, 15
Click, 2342, 381, 0
Click, 2350, 389, 0
Sleep, 16
Click, 2354, 393, 0
Sleep, 16
Click, 2358, 399, 0
Click, 2359, 401, 0
Sleep, 31
Click, 2360, 402, 0
Click, 2362, 403, 0
Sleep, 16
Click, 2364, 404, 0
Sleep, 15
Click, 2368, 405, 0
Click, 2374, 406, 0
Sleep, 16
Click, 2383, 409, 0
Sleep, 15
Click, 2385, 409, 0
Click, 2386, 409, 0
Sleep, 141
Click, 2382, 408, 0
Click, 2375, 403, 0
Sleep, 16
Click, 2350, 389, 0
Sleep, 15
Click, 2281, 339, 0
Sleep, 16
Click, 2239, 316, 0
Sleep, 16
Click, 2154, 267, 0
Sleep, 15
Click, 2085, 233, 0
Sleep, 16
Click, 2038, 208, 0
Sleep, 15
Click, 2028, 201, 0
Click, 2022, 195, 0
Sleep, 16
Click, 2021, 194, 0
Sleep, 94
Click, 2024, 194, 0
Click, 2026, 194, 0
Sleep, 78
Click, 2027, 195, 0
Sleep, 47
Click, 2027, 209, 0
Click, 2026, 213, 0
Sleep, 15
Click, 2025, 214, 0
Click, 2025, 216, 0
Sleep, 47
Click, 2024, 217, 0
Sleep, 32
Click, 2021, 217, 0
Sleep, 15
Click, 2019, 217, 0
Sleep, 16
Click, 2017, 217, 0
Sleep, 15
Click, 2014, 217, 0
Sleep, 16
Click, 2013, 217, 0
Sleep, 16
Click, 2011, 217, 0
Sleep, 15
Click, 2009, 217, 0
Sleep, 16
Click, 2008, 217, 0
Click, 2006, 217, 0
Sleep, 16
Click, 2005, 217, 0
Sleep, 15
Click, 2002, 217, 0
Sleep, 16
Click, 2000, 216, 0
Sleep, 15
Click, 1999, 215, 0
Sleep, 235
Click, 1998, 215, 0
Sleep, 31
Click, 1996, 215, 0
Sleep, 16
Click, 1995, 215, 0
Sleep, 15
Click, 1994, 215, 0
Sleep, 391
Click, 1993, 215, 0
Sleep, 16
Click, 1993, 216, 0
Sleep, 15
Click, 1993, 221, 0
Click, 1993, 224, 0
Sleep, 203
Click, 1992, 225, 0
Sleep, 16
Click, 1991, 225, 0
Sleep, 16
Click, 1990, 224, 0
Sleep, 15
Click, 1990, 223, 0
Sleep, 110
Click, 1990, 222, 0
Sleep, 62
Click, 1990, 221, 0
Sleep, 78
Click, 1990, 220, 0
Sleep, 78
Click, 1991, 219, 0
Sleep, 78
Click, 1992, 219, 0
Sleep, 204
Click, 1993, 218, 0
Sleep, 31
Click, 1994, 218, 0
Sleep, 125
Click, 1994, 216, 0
Sleep, 203
WinActivate, Program Manager ahk_class Progman
Click, 2308, 383 Left, Down
Sleep, 109
Click, 2308, 383 Left, Up
Sleep, 688
Click, 2303, 387, 0
Sleep, 15
Click, 2301, 387, 0
Sleep, 47
Click, 2296, 387, 0
Sleep, 16
Click, 2258, 390, 0
Sleep, 16
Click, 2198, 390, 0
Sleep, 31
Click, 2132, 390, 0
Sleep, 15
Click, 2111, 390, 0
Sleep, 16
Click, 2103, 390, 0
Sleep, 31
Click, 2099, 390, 0
Sleep, 16
Click, 2082, 390, 0
Sleep, 16
Click, 2062, 390, 0
Click, 2051, 390, 0
Sleep, 31
Click, 2031, 390, 0
Sleep, 31
Click, 2028, 390, 0
Sleep, 63
Click, 2026, 390, 0
Sleep, 15
Click, 2021, 390, 0
Sleep, 16
Click, 2020, 390, 0
Sleep, 78
Click, 2017, 390, 0
Sleep, 16
Click, 2015, 390, 0
Sleep, 15
Click, 2008, 390, 0
Sleep, 31
Click, 2000, 390, 0
Sleep, 16
Click, 1998, 390, 0
Sleep, 47
Click, 1997, 390, 0
Sleep, 16
Click, 1993, 390, 0
Sleep, 31
Click, 1986, 390, 0
Sleep, 15
Click, 1980, 390, 0
Click, 1977, 390, 0
Sleep, 32
Click, 1976, 390, 0
Sleep, 15
Click, 1975, 390, 0
Sleep, 32
Click, 1970, 391, 0
Sleep, 15
Click, 1955, 394, 0
Sleep, 31
Click, 1947, 394, 0
Sleep, 16
Click, 1944, 395, 0
Sleep, 63
Click, 1943, 395, 0
Sleep, 15
Click, 1940, 395, 0
Sleep, 31
Click, 1938, 395, 0
Sleep, 63
Click, 1937, 395, 0
Sleep, 31
Click, 1936, 395, 0
Click, 1935, 395, 0
Sleep, 31
Click, 1930, 395, 0
Sleep, 32
Click, 1929, 395, 0
Sleep, 15
Click, 1928, 395, 0
Sleep, 32
Click, 1927, 395, 0
Sleep, 15
Click, 1926, 395, 0
Sleep, 31
Click, 1923, 395, 0
Sleep, 32
Click, 1920, 395, 0
Sleep, 15
Click, 1919, 395, 0
Sleep, 63
Click, 1918, 395, 0
Sleep, 15
Click, 1917, 395, 0
Sleep, 32
Click, 1915, 395, 0
Sleep, 109
Click, 1914, 395, 0
Sleep, 16
Click, 1913, 395, 0
Sleep, 31
Click, 1912, 395, 0
Critical Off
Return
User avatar
Flarebrass
Posts: 104
Joined: 20 Nov 2015, 13:13
Location: USA
Contact:

Re: dealing with multiple scripts

29 Apr 2016, 06:47

That would make it a bit more difficult since they are two separate scripts. If you combine them into the same script, you can easily use Critical as I've mentioned. If they are in two separate scripts, you'll need to use SendMessage and OnMessage() to communicate between the scripts. I try to make all of my scripts in such a way that they don't interfere with one another, or I'm still in the process of making a type of kernal which will add any new scripts and script changes as modules to a permanently running background program so that it can manage all of my scripts simultaneously and not cause issues like you have here.

What I would recommend as a very newbie thing to do is make each script start with a different hotkey, then only press one hotkey for one script to activate, and manually wait until it finishes executing before pressing the other hotkey. Another way would be to combine the scripts and do a few adjustments to the program flow, but it could be as simple as this:

Code: Select all

Numpad1::
;copy and paste script 1

Numpad2::
;copy and paste script 2
(Note that I can't test my code before posting, so beware of bugs! -Flarebrass Amatzikahni)
nicolo
Posts: 23
Joined: 28 Apr 2016, 04:57

Re: dealing with multiple scripts

29 Apr 2016, 15:07

thank you for helping me!
just to make sure my need is clear :
these 2 .exe scripts will be launched by other applications of mine. I won't launch them manually. This is why I don't want to use hotkeys.
so sometimes, 2 applications could launch 2 .exe scripts like these ones at the same time.
I can't do so that the scripts are not launched at the same time, because they will be launched by applications. And the launch itself will be caused following external events.
In the above example, 2 .exe scripts are launched at the same time, but there could be 3, 4 or more...
I guess this is not clear at all, but what I mean is that I can't manage when the scripts are launched and therefore they can be launched more or less at the same time.
So my need is that they don't interfer.
When 2 scripts (or more) are simultaneously launched, I'd like the first one to go until the end. In the meantime, the second one (by order of launching time) should be placed in queue and the start after the 1st one is over. And so on...
User avatar
Flarebrass
Posts: 104
Joined: 20 Nov 2015, 13:13
Location: USA
Contact:

Re: dealing with multiple scripts

02 May 2016, 05:10

Then you will find SendMessage and OnMessage() to be the functions of choice to communicate between the scripts. The examples are great teaching tools, but I haven't messed with them so my syntax and logic will be wrong if I try to post something.
(Note that I can't test my code before posting, so beware of bugs! -Flarebrass Amatzikahni)

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], famko, Sharon, teadrinker and 35 guests