AutoScriptWriter宏不起作用

时间:2013-04-02 23:11:35

标签: autohotkey

我创建了一个小宏,用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

1 个答案:

答案 0 :(得分: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,定义Noise Sample以单击“Define Noise Sample”窗口中的OK按钮。

我分配了一个热键[Alt] + v,但你可以创建你喜欢的任何组合。
! = 替代
^ = Ctrl
 #=
+ = Shift

因此
!t = Alt + t
^ + F2 = Ctrl + Shift + F2
 #w = + w

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