Join 3 Scripts in one multi container. Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
AutoX
Posts: 13
Joined: 14 May 2022, 12:14

Join 3 Scripts in one multi container.

Post by AutoX » 15 May 2022, 16:15

Good morning, is possible join 3 Scripts in one multi script container and activate each one with Left arrow, Up arrow and Right arrow.
The 3 Scripts are similar, the main function of each differs only in time execution.
I like activate: Left Arrow (activate Script 1), Up Arrow (activate Script 2), Right Arrow (activate Script 3). Thanks.


Suspend
#NoEnv
#SingleInstance force
~LButton::RButton [[[ SCRIPT 1]]]
return
Home::Suspend
End::ExitApp
---------------
suspend
#NoEnv
#SingleInstance force
[[[ SCRIPT 2]]]
return
Home::Suspend
End::ExitApp
------------
suspend
#NoEnv
#SingleInstance force
[[[ SCRIPT 3]]]
return
Home::Suspend
End::ExitApp
Last edited by AutoX on 15 May 2022, 20:26, edited 1 time in total.

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Helpl please, join 3 Scripts in one multi container.  Topic is solved

Post by mikeyww » 15 May 2022, 18:41

Code: Select all

Left:: script = 1
Up::   script = 2
Right::script = 3

#If (script = 1)
LButton::RButton

#If (script = 2)
LButton::x

#If (script = 3)
LButton::y
#If

AutoX
Posts: 13
Joined: 14 May 2022, 12:14

Re: Helpl please, join 3 Scripts in one multi container.

Post by AutoX » 17 May 2022, 16:49

Thanks ahother question please: The container works perfectly but I can't "run only in the Game Window" (Game in Windowed mode 1024 x 768 not full screen). I added "#IfWinActive MyGame.exe" but Script also "run outside Game" (in all Windows system). How fix please Thank you.

Code: Select all

Suspend
#NoEnv
#SingleInstance force
#IfWinActive MyGame.exe  <-- <-- <--
#IfWinActive <-- <-- <--
Left:: script = 1
Up::   script = 2
Right::script = 3
#If (script = 1)
~LButton::RButton
#If (script = 2)
Script 2
#If (script = 3)
Script 3
Home::Suspend
End::ExitApp

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Join 3 Scripts in one multi container.

Post by mikeyww » 17 May 2022, 17:30

Use a :arrow: WinTitle instead of just a process name alone. https://www.autohotkey.com/docs/misc/WinTitle.htm#ahk_exe

Code: Select all

winTitle = ahk_exe MyGame.exe

#If WinActive(winTitle)
Left:: script = 1
Up::   script = 2
Right::script = 3

#If WinActive(winTitle) && script = 1
LButton::RButton

#If WinActive(winTitle) && script = 2
LButton::x

#If WinActive(winTitle) && script = 3
LButton::y
#If
Explained: #If
Like the #IfWin directives, #If is positional: it affects all hotkeys and hotstrings physically beneath it in the script. #If and #IfWin are also mutually exclusive; that is, only the most recent #If or #IfWin will be in effect.

AutoX
Posts: 13
Joined: 14 May 2022, 12:14

Re: Join 3 Scripts in one multi container.

Post by AutoX » 17 May 2022, 20:16

Thanks, but error continue. The objetive is Script runs only in the game (mode windowed, not full screen), but I go to desktop or another application and it continues run, even with this modification.

Code: Select all

Suspend
#NoEnv
#SingleInstance, force
winTitle = ahk_exe MyGame.exe

#If WinActive(winTitle)
Left:: script = 1
Up::   script = 2
Right::script = 3

#If WinActive(winTitle) && script = 1
Script 1

#If WinActive(winTitle) && script = 2
Script 2

#If WinActive(winTitle) && script = 3
Script 3
#If

Home::Suspend
Down::ExitApp

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Join 3 Scripts in one multi container.

Post by mikeyww » 17 May 2022, 20:28

You are showing just a script fragment, impossible to debug here. The window is checked only when the hotkey is triggered. You could run a SetTimer to check for changes, or use WinWaitActive.

#If applies only to hotstrings and hotkeys. See documentation.

AutoX
Posts: 13
Joined: 14 May 2022, 12:14

Re: Join 3 Scripts in one multi container.

Post by AutoX » 17 May 2022, 21:01

Sorry but i dont know how make run only in the game. I'll try to post on the forum.
Script complete is:

Code: Select all

Suspend
#NoEnv
#SingleInstance, force
winTitle = ahk_exe MyGame.exe
#If WinActive(winTitle)
Left:: script = 1
Up::   script = 2
Right::script = 3
#If WinActive(winTitle) && script = 1
~LButton::RButton
Return
#If WinActive(winTitle) && script = 2
~RButton::LButton
Return
#If WinActive(winTitle) && script = 3
~LButton::
while GetKeyState("LButton", "P")
Send,{RButton Down}
KeyWait,LButton
Send,{RButton Up}
Return
Home::Suspend
Down::ExitApp

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Join 3 Scripts in one multi container.

Post by mikeyww » 17 May 2022, 21:08

After restoring the closing #If that I posted, I had no trouble with this in Notepad. Try it there to test it and see how it works.

Your final routine with While does not make sense to me. I am not sure of your intent there. Whether you intend a block is unclear. The role of KeyWait is also unclear to me.

Code: Select all

Suspend
winTitle = ahk_exe MyGame.exe
winTitle = ahk_exe notepad.exe

Home::Suspend
Down::ExitApp

#If WinActive(winTitle)
Left:: script = 1
Up::   script = 2
Right::script = 3

#If WinActive(winTitle) && script = 1
~LButton::RButton

#If WinActive(winTitle) && script = 2
~RButton::LButton

#If WinActive(winTitle) && script = 3
~LButton::
While GetKeyState("LButton", "P")
 Click, R
Return
#If

AutoX
Posts: 13
Joined: 14 May 2022, 12:14

Re: Join 3 Scripts in one multi container.

Post by AutoX » 17 May 2022, 22:10

Thanks, it's still running outside game, Maybe Macros are the problem. Clicking outside Game macro don't stop, sometimes right click stop it outside but generally force close Script. I tried other options and don't work, just ~LButton::RButton work in my Game.

Code: Select all

~LButton::RButton
work ok in Game but run outside (no stop)

User avatar
mikeyww
Posts: 26591
Joined: 09 Sep 2014, 18:38

Re: Join 3 Scripts in one multi container.

Post by mikeyww » 18 May 2022, 05:08

You did not provide any information about use in Notepad, but if you are concurrently running any scripts, macros, keyboard or mouse software utilities, etc., they could conflict.

Post Reply

Return to “Ask for Help (v1)”