Autohotkey v2 脚本 |复制,打开应用程序,粘贴

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

我想选择文本,按热键触发应用程序打开,将所选文本粘贴到新打开的应用程序中。就我而言,我的应用程序称为 everything,Windows 上的文件定位器。保存在D盘下,并更新到最新版本。

这是我的代码:

#f::
{
    A_Clipboard := ""
    ; Copy selected text to clipboard
    Send "^c"
    ClipWait ; Wait for 2 seconds for clipboard to contain text
    SetTitleMatchMode 2
    
    if WinExist("*everything*")
        {
        WinActivate 
        MsgBox "Everything was found."
        }
        ; Use the window found by WinExist.
    else {
        Run "D:\Downloads\everything\Everything.exe"
        Sleep 1000  
        SendInput A_Clipboard
        Send "^v"
        MsgBox "Everything was not found."
        }    
}

此脚本复制所选文本,打开应用程序。 问题是它不会将选定的文本粘贴到 Everything 中。

如果我手动按 ctrl+V,所选文本将粘贴到 Everything 中的搜索窗口中。 WinExist找不到Everything,我用消息框进行了测试。 Everything 的 winTitle 是“everything.exe”。

请帮忙。谢谢你。

autohotkey ahk2
1个回答
0
投票

试试这个方法:

#Requires AutoHotkey v2.0

#f::
{
    A_Clipboard := ""
    ; Copy selected text to clipboard
    Send "^c"
    if !ClipWait(2)
    {
        MsgBox "The attempt to copy text onto the clipboard failed."
        return
    }
    Run "D:\Downloads\everything\Everything.exe" " -s " A_Clipboard
}
© www.soinside.com 2019 - 2024. All rights reserved.