0

I want to pass the window title into a function I wrote in AutoHotKey, is window title WinTitle a string? I have 4 window titles, and I need to pass them to the same function.

Extract(my_window_title) {
; Wake and select the correct window to be in focus
WinWait, my_window_title, 
IfWinNotActive, my_window_title, , WinActivate, my_window_title, 
WinWaitActive, my_window_title,
; ... do a bunch of things
}

I call the function like this

title1 = "Some title"
Extract(title1) 

and I also tried putting % in all the variables

4

2 回答 2

2

是的 WinTitle 基本上是一个字符串。检查您的 Autohotkey 文件夹,应该有一个名为“AU3_Spy.exe”的文件。使用它来查找窗口标题。

正如 Elliot DeNolf 已经提到的,你在变量方面犯了一些错误。您还应该再看一下 IfWINNotActive 的语法。这应该有效:

Extract(my_window_title) {
    ; Wake and select the correct window to be in focus
    WinWait, %my_window_title%
    IfWinNotActive, %my_window_title%
    {
        WinActivate, %my_window_title%
        WinWaitActive, %my_window_title%
    }
    msgbox, %my_window_title%
    ; ... do a bunch of things
}

title1 = MyWindowTitle
Extract(title1) ;functions always expect variables, no percent-signs here
于 2013-11-07T11:22:36.577 回答
1

There are a few things that look like they are causing an issue in your script.

When assigning a string value and using =, quotes are not needed. If you assign the value using :=, then you need the quotes. These 2 lines are equivalent:

    title1 := "Some Title"
    title1 = Some Title

Once these values are called via a function ie. Extract(title1), % symbols must be used (as you mentioned at the end of your question). This can be called in 2 ways:

    WinActivate, %my_window_title%
    WinActivate, % my_window_title

If the title is invalid, your script will wait indefinitely on WinWait and WinWaitActive. I would recommend using a timeout value and then checking ErrorLevel to see if it was successful or not.

于 2013-11-06T18:13:14.450 回答