跨所有窗口自动热键搜索

问题描述 投票:0回答:1

我正在尝试创建一个脚本,用于搜索 Word、Pdf、Excel 和 Chrome 选项卡中突出显示的内容(如果它们在我运行脚本时打开)。

问题是我试图通过按一个键来完成这一切。脚本看起来像这样,但它不能正常工作:

Send, ^c
WinGetClass, class, A
MsgBox, The active window's class is "%class%"
;SetKeyDelay, 0
if WinExist("ahk_class OpusApp")
{
    WinActivate
    Send, ^f
    gosub getplain
    SetKeyDelay, 0
    Send {Raw}%clipboardt%
    ;clipboardt := ""
    ;return
}
;SetKeyDelay, 0

if WinExist("ahk_class AcrobatSDIWindow")
{
    WinActivate
    Send, ^f
    gosub getplain
    SetKeyDelay, 0
    Send {Raw}%clipboardt%
    ;clipboardt =
    ;return
}
;SetKeyDelay, 0

if WinExist("ahk_class XLMAIN")
{
    WinActivate
    Send, ^f
    gosub getplain
    SetKeyDelay, 0
    Send {Raw}%clipboardt%
    ;clipboardt =
    ;return
}
;SetKeyDelay, 0
if WinExist("ahk_class Chrome_WidgetWin_1")
{
    WinActivate
    Send, ^f
    gosub getplain
    SetKeyDelay, 0
    Send {Raw}%clipboardt%
    ;clipboardt =
}
;SetKeyDelay, 0
if WinExist("ahk_exe firefox.exe")
{
    WinActivate
    Send, ^f
    gosub getplain
    SetKeyDelay, 0
    Send {Raw}%clipboardt%
    ;clipboardt =
}


getplain:
StringReplace, clipboardt, clipboard, `r`n, %A_Space%, All
clipboardt := RegExReplace(clipboardt, "` {2,}", "` ")
StringLeft, 1st, clipboardt, 1
IfInString, 1st, %A_Space%
StringTrimLeft, clipboardt, clipboardt, 1
StringRIght, last, clipboardt, 1
IfInString, last, %A_Space%
StringTrimRight, clipboardt, clipboardt, 1



return

}

你有什么建议吗?一键脚本太多了吗?

我不知道什么不起作用:/

search full-text-search autohotkey
1个回答
0
投票

试试这个:

; Create an array of those windows:
my_windows := ["OpusApp", "AcrobatSDIWindow", "XLMAIN", "Chrome_WidgetWin_1"," MozillaWindowClass"]

#If WinExist("ahk_class OpusApp") || WinExist("ahk_class AcrobatSDIWindow") || WinExist("ahk_class XLMAIN") || WinExist("ahk_class Chrome_WidgetWin_1") || WinExist("ahk_class MozillaWindowClass") ; || mens OR

    F1::
        clipboard := ""  ; empty the clipboard (start off empty to allow ClipWait to detect when the text has arrived)
        Send, ^c         ; copy the selected text
        ClipWait 1       ; wait max. 1 sec for the clipboard to contain data
        If (ErrorLevel)
        {
            MsgBox, No text copied
            return
        }
        ; otherwise:            
        clipboard := Trim(clipboard, ", `t`r`n") ; remove leading and trailing commas, spaces, tabs, CRs and LFs 
        For each, window in my_windows           ; retrieve each window from the array, one at a time
        {
            If WinExist("ahk_class" window)
            {
                WinActivate
                WinWaitActive
                Send, ^f
                Sleep, 200
                Send, ^v
                Sleep, 200
                SendInput, {Enter}
            }
        }
    return

#If
© www.soinside.com 2019 - 2024. All rights reserved.