2017-03-13 49 views
0

我試圖做一個ahk腳本,當打開一個新窗口(或帶回焦點)時提醒您。換句話說,我想讓它檢測當前窗口的變化。我試着比較窗口的名稱來檢測差異:當前窗口變化時AutoHotkey GetWinTitle

0:: 
    WinGetTitle, title, A 
    windowTitle=%title% 
    MsgBox, "The current window is %title%." 
    return 

    9:: 
    WinGetTitle, title2, A 
    if (%title2% = %title%) 
    { 
     success=1 
    } 
    else 
    { 
     MsgBox, "The current window changed to %title2%." 
    } 
    return 

但是, 我顯然使用的變量非法字符
1);和
2)我寧願使用不同的方法比這個;

在此先感謝!

P.S.我希望警報包含當前窗口的名稱。

+0

在'if'中使用括號時,不要使用'%',因爲變量已被自動展開。 – wOxxOm

+0

哇!有效!當我讀取錯誤消息時,我看着我,好像我不能在變量中使用引號。謝謝! – Anonymous

+0

參見[SetTimer - Example2](https://autohotkey.com/docs/commands/SetTimer.htm#Examples)。 – user3419297

回答

2
CurrentTitle := "" 

SetTimer, CheckWindow, 1000 
return 

CheckWindow: 
    WinGetTitle, NewTitle, A 
    if (CurrentTitle != NewTitle){ 
     ToolTip % "Window changed to: " NewTitle 
     CurrentTitle := NewTitle 
    } 
    return 
+0

我寧願使用'setTimer',因此腳本執行不會阻止 – Blauhirn

+0

@Blauhirn - 已更新爲使用SetTimer –

相關問題