Autohotkey:Merging/combining 一个脚本中的两个脚本(#if WinActive,2 个操作)
Autohotkey: Merging/combining two scripts in one script (#if WinActive, 2 actions)
我有 2 个脚本想合并到一个文件中,但是当我将它们放在一起时,只有第一个脚本被执行:
脚本 1:
#if WinActive("ahk_exe program.EXE")
#Persistent
Loop
{
WinWaitActive, Wizard
Send, !{F4}
}
Return
脚本 2:
#if WinActive("ahk_exe program2.EXE")
#Persistent
Loop
{
WinWait, ahk_class bosa_sdm_Mso96
; IfWinNotActive, ahk_class bosa_sdm_Mso96, ,WinActivate, ahk_class bosa_sdm_Mso96
; WinWaitActive, ahk_class bosa_sdm_Mso96
; Sleep, 0
ControlMove, RichEdit20W6, 20, 850, 750, 25 ;Adress box
ControlMove, SysTreeView321, , , 800, 700
ControlMove, TreeViewCFParent1, , , 1000, 700
ControlMove, SysTreeView322, , , 800, 700
ControlMove, TreeViewParent1, , , 760, 940
WinMove, ahk_class bosa_sdm_Mso96, , 600, 50, 1000, 900 ; 900 width
}
Return
我尝试删除或更改“#Persistent”、"Loop"、"Return".. 的位置或在每个脚本的末尾添加#if.. 仍然只有第一个被执行.. 即使尝试在第二个脚本中#Include 第一个脚本,第一个脚本也只会被执行。也许它需要 "else" 或其他东西..不确定..
#If directive 仅用于创建上下文相关的热键和热字串。
如果您使用 WinWait 或 WinWaitActive 脚本会一直等到(第一个)window 存在或变为活动状态,并且不会' 进一步移动第二个 window.
没有 WinWait,CPU 脚本的使用率很高。
在这种情况下更好的解决方案是 SetTimer:
#Persistent
SetTimer, Close_Move_Windows, 500
return
Close_Move_Windows:
IfWinActive, Wizard
WinClose
IfWinExist, ahk_class bosa_sdm_Mso96
{
WinGetPos, X, Y, Width, Height, ahk_class bosa_sdm_Mso96
If (X != 600 || Y != 50 || Width != 900 || Height != 1000) ; "!" means "NOT" and "||" means "OR"
{
ControlMove, RichEdit20W6, 20, 850, 750, 25 ;Adress box
ControlMove, SysTreeView321, , , 800, 700
ControlMove, TreeViewCFParent1, , , 1000, 700
ControlMove, SysTreeView322, , , 800, 700
ControlMove, TreeViewParent1, , , 760, 940
WinMove, ahk_class bosa_sdm_Mso96,, 600, 50, 900, 1000 ; 900 width
}
}
Return
我有 2 个脚本想合并到一个文件中,但是当我将它们放在一起时,只有第一个脚本被执行:
脚本 1:
#if WinActive("ahk_exe program.EXE")
#Persistent
Loop
{
WinWaitActive, Wizard
Send, !{F4}
}
Return
脚本 2:
#if WinActive("ahk_exe program2.EXE")
#Persistent
Loop
{
WinWait, ahk_class bosa_sdm_Mso96
; IfWinNotActive, ahk_class bosa_sdm_Mso96, ,WinActivate, ahk_class bosa_sdm_Mso96
; WinWaitActive, ahk_class bosa_sdm_Mso96
; Sleep, 0
ControlMove, RichEdit20W6, 20, 850, 750, 25 ;Adress box
ControlMove, SysTreeView321, , , 800, 700
ControlMove, TreeViewCFParent1, , , 1000, 700
ControlMove, SysTreeView322, , , 800, 700
ControlMove, TreeViewParent1, , , 760, 940
WinMove, ahk_class bosa_sdm_Mso96, , 600, 50, 1000, 900 ; 900 width
}
Return
我尝试删除或更改“#Persistent”、"Loop"、"Return".. 的位置或在每个脚本的末尾添加#if.. 仍然只有第一个被执行.. 即使尝试在第二个脚本中#Include 第一个脚本,第一个脚本也只会被执行。也许它需要 "else" 或其他东西..不确定..
#If directive 仅用于创建上下文相关的热键和热字串。
如果您使用 WinWait 或 WinWaitActive 脚本会一直等到(第一个)window 存在或变为活动状态,并且不会' 进一步移动第二个 window.
没有 WinWait,CPU 脚本的使用率很高。
在这种情况下更好的解决方案是 SetTimer:
#Persistent
SetTimer, Close_Move_Windows, 500
return
Close_Move_Windows:
IfWinActive, Wizard
WinClose
IfWinExist, ahk_class bosa_sdm_Mso96
{
WinGetPos, X, Y, Width, Height, ahk_class bosa_sdm_Mso96
If (X != 600 || Y != 50 || Width != 900 || Height != 1000) ; "!" means "NOT" and "||" means "OR"
{
ControlMove, RichEdit20W6, 20, 850, 750, 25 ;Adress box
ControlMove, SysTreeView321, , , 800, 700
ControlMove, TreeViewCFParent1, , , 1000, 700
ControlMove, SysTreeView322, , , 800, 700
ControlMove, TreeViewParent1, , , 760, 940
WinMove, ahk_class bosa_sdm_Mso96,, 600, 50, 900, 1000 ; 900 width
}
}
Return