0

我用 AutoScriptWriter 创建了一个小宏,它在我创建后立即运行良好,但后来当我打开它正在工作的程序并启动宏时,它出现在我的系统托盘中,但什么也没发生。我还没有分配热键,只是单击宏来运行它。我究竟做错了什么?

谢谢,艾伦

#NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
; #Warn  ; Enable warnings to assist with detecting common errors.
SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.

run C:\Program Files\VinylStudio\VinylStudio.exe, , max

#SingleInstance Force
#installKeybdHook
#Persistent

SetTitleMatchMode, 2 ;  Allow more flexibility in matching the windows title.
SetTimer, CloseScript, 1000
Return ; stop the script here on startup

CloseScript:
IfWinExist ahk_class VinylStudio_main
    Return
ExitApp

#ifWinActive ahk_class VinylStudio_main

^h:: ; Here I assigned the hotkey [Ctrl]+h

WinActivate, VinylStudio
WinWait, VinylStudio, , 3 ; Wait for 3 seconds and then alert user
if ErrorLevel
{
    MsgBox, VinylStudio timed out.
    return
}
MouseClick, left,  479,  79 ; MouseClicks are less reliable than keyboard shortcuts or ControlSend/ControlClick.
Sleep, 100
MouseClick, left,  421,  40
Sleep, 100
MouseClick, left,  425,  443
Sleep, 100
WinWait, Filter Settings, , 3 ; Wait 3 seconds for pop-up else alert user
if ErrorLevel
{
    MsgBox, Filter Settings timed out.
    return
}
MouseClick, left,  29,  109
Sleep, 100
WinWait, Define Noise Sample, , 3 ; Wait 3 seconds for pop-up else alert user
if ErrorLevel
{
    MsgBox, Define Noise Sample timed out.
    return
}
MouseClick, left,  388,  168
Sleep, 100
MouseClick, left, -86,  660, 2
;MouseClick, left, -86,  660
Sleep, 100
WinWait, VinylStudio, , 3 ; Wait 3 seconds for pop-up else alert user
if ErrorLevel
{
    MsgBox, VinylStudio timed out.
    return
}
MouseClick, left,  200,  675, 2
;MouseClick, left,  200,  675
Sleep, 100
MouseClick, left,  200,  675, 2
;MouseClick, left,  200,  675
Sleep, 100
MouseClick, left,  201,  673
Sleep, 100
MouseClick, left,  203,  673, 2
;MouseClick, left,  203,  673
Sleep, 100
MouseClick, left,  203,  673
Sleep, 100
MouseClick, left,  787,  645
Sleep, 100
Return


#ifwinactive
4

1 回答 1

1

好的,我看过了。在当前代码中,您确实检查了很多,但永远不知道您的检查失败的地方。

这是一些清理代码的开始:

#SingleInstance Force
#installKeybdHook
#Persistent
SetTitleMatchMode, 2 ;  Allow more flexibility in matching the windows title.
Return ; stop the script here on startup

!v:: ; Here I assigned the hotkey [Alt]+v
;IfWinNotExist, VinylStudio ; Line could be removed if VS is running
;    Run, VinylStudio.exe Collection.mcf ; Line could be removed
WinActivate, VinylStudio
WinWait, VinylStudio, , 3 ; Wait for 3 seconds and then alert user
if ErrorLevel
{
    MsgBox, VinylStudio timed out.
    return
}
MouseClick, left,  479,  79 ; MouseClicks are less reliable than keyboard shortcuts or ControlSend/ControlClick.
Sleep, 100
MouseClick, left,  421,  40
Sleep, 100
MouseClick, left,  425,  443
Sleep, 100
WinWait, Filter Settings, , 3 ; Wait 3 seconds for pop-up else alert user
if ErrorLevel
{
    MsgBox, Filter Settings timed out.
    return
}
MouseClick, left,  29,  109
Sleep, 100
WinWait, Define Noise Sample, , 3 ; Wait 3 seconds for pop-up else alert user
if ErrorLevel
{
    MsgBox, Define Noise Sample timed out.
    return
}
MouseClick, left,  388,  168
Sleep, 100
MouseClick, left, -86,  660, 2
;MouseClick, left, -86,  660
Sleep, 100
WinWait, VinylStudio, , 3 ; Wait 3 seconds for pop-up else alert user
if ErrorLevel
{
    MsgBox, VinylStudio timed out.
    return
}
MouseClick, left,  200,  675, 2
;MouseClick, left,  200,  675
Sleep, 100
MouseClick, left,  200,  675, 2
;MouseClick, left,  200,  675
Sleep, 100
MouseClick, left,  201,  673
Sleep, 100
MouseClick, left,  203,  673, 2
;MouseClick, left,  203,  673
Sleep, 100
MouseClick, left,  203,  673
Sleep, 100
MouseClick, left,  787,  645
Sleep, 100
Return

艾伦,尽量避免点击坐标。更好的方法是例如使用 ControlSend 或 ControlClick 并将信息/点击发送到特定对象。您通常可以使用 AHK Windows Spy(在 classNN 下)找到对象名称。ControlClick 可能如下所示:ControlClick、Toolbar321、VinylStudio 或 ControlClick、OK、Define Noise Sample 以单击“Define Noise Sample”窗口中的 OK 按钮。

我指定了一个热键 [Alt]+v,但您可以创建任何您喜欢的组合。
!= Alt,
^ = Ctrl,
# = Win,
+ = Shift.

所以
!t = Alt+ t
^+F2 = Ctrl+ Shift+F2
#w = Win+w

在热键之后,我仍然检查 VS 是否正在运行,如果没有,我将启动它,但您可以删除这些行并将热键放在 WinActivate、VinylStudio 上方

于 2013-04-03T12:39:50.730 回答