Page 1 of 1

Join 3 Scripts in one multi container.

Posted: 15 May 2022, 16:15
by AutoX
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

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

Posted: 15 May 2022, 18:41
by mikeyww

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

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

Posted: 17 May 2022, 16:49
by AutoX
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

Re: Join 3 Scripts in one multi container.

Posted: 17 May 2022, 17:30
by mikeyww
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.

Re: Join 3 Scripts in one multi container.

Posted: 17 May 2022, 20:16
by AutoX
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

Re: Join 3 Scripts in one multi container.

Posted: 17 May 2022, 20:28
by mikeyww
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.

Re: Join 3 Scripts in one multi container.

Posted: 17 May 2022, 21:01
by AutoX
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

Re: Join 3 Scripts in one multi container.

Posted: 17 May 2022, 21:08
by mikeyww
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

Re: Join 3 Scripts in one multi container.

Posted: 17 May 2022, 22:10
by AutoX
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)

Re: Join 3 Scripts in one multi container.

Posted: 18 May 2022, 05:08
by mikeyww
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.