2016-03-25 6 views
0

私はF9キーを押したときにAdobe Acrobatからテキストをコピーするように設計されたAHKスクリプトを作成しました。正規表現に従ってそれを変更し、コピーしたテキストをツールチップに表示します。さらに、Acrobatに悪意のあるテキストをコピーするときにAcrobatが表示する厄介なウィンドウを自動的に閉じるコードを追加しましたThere was an error while copying to Clipboard. An internal error occurred.このウィンドウが表示されない場合、スクリプトは特定の時間後に閉じるように設計されたツールチップを表示し続けます。私は壁に向かって頭を叩いていますが、これを修正する方法はわかりません。AHK:ポップアップ時にウィンドウを閉じる

;#NoTrayIcon 
#Persistent 
#SingleInstance 
F9:: 
#If WinActive("ahk_exe Acrobat.exe") 
{ 
Clipboard:="" 
send,^c 
ClipWait, 1 
Clipboard := RegExReplace(Clipboard, "\r\n", " ") 
SetTimer,CheckForMsgBox,100 
CheckForMsgBox: 
    IfWinExist, Adobe Acrobat 
    { 
     Send {Enter} 
     SetTimer,CheckForMsgBox,Off 
    } 
;Return 
If (StrLen(Clipboard) < 120) 
ToolTip % Clipboard 
Else 
ToolTip Copied 
SetTimer, ToolTipOff, -1000 
return 
} 
#If 

ToolTipOff: 
ToolTip 
return 
+0

希望する動作と問題点を明確にしてください。スクリプトの途中で 'CheckForMsgBox'の目的は何ですか? – 2501

答えて

2
;#NoTrayIcon 
; #Persistent ; (1) 
#SingleInstance 
SetTimer,CheckForMsgBox,100 ; (2) 
return 

#If WinActive("ahk_exe Acrobat.exe") ; (3) 

F9::  
clipboard:="" 
send,^c 
ClipWait, 1 
Clipboard := RegExReplace(Clipboard, "\r\n", " ") 
If (StrLen(Clipboard) < 120) 
    ToolTip %Clipboard% 
Else 
    ToolTip Copied 
SetTimer, ToolTipOff, -1000 
return 

#If ; turn off context sensitivity 

ToolTipOff: 
ToolTip 
return 

CheckForMsgBox: 
; ControlSend, Control, Keys, WinTitle, WinText, ExcludeTitle, ExcludeText 
ControlSend, , {Enter}, Adobe Acrobat ; Close this unwanted window whenever it appears 
return 

は、(1)ホットキー、hotstrings、またはのonMessage()またはGUIのいずれかの使用を含むスクリプトが自動的永続あります。

(2)SetTimerは、指定された時間間隔で自動的にサブルーチン(Label)を繰り返し起動します。

https://autohotkey.com/docs/commands/SetTimer.htm

(3)#IfWinディレクティブと同様に、#If文は位置である:それは、スクリプト内で物理的に下の全てのホットキーとhotstringsに影響を与えます。

https://autohotkey.com/docs/commands/_If.htm

+0

素晴らしい作品です。私は本当にあなたの答えとあなたの発言に感謝します! – menteith