以下代码在按 ctrl+shift+c 后从文件中获取选定的文本,并将其名称和路径附加到其中,然后将其复制到剪贴板。它适用于 .txt 文件,但不适用于 pdf 文件。我怎样才能让它与pdf文件一起工作?
#NoEnv ; Recommended for performance and compatibility with future AutoHotkey releases.
SendMode Input ; Recommended for new scripts due to its superior speed and reliability.
SetWorkingDir %A_ScriptDir% ; Ensures a consistent starting directory.
; **Hotkey to trigger the script**
^+c::
ClipWait, 1 ; Wait for the clipboard to contain text (timeout after 1 second).
; Retrieve the active window title (potential file name)
WinGetActiveTitle, active_title
; Check if the window title appears relevant to a file
if (RegExMatch(active_title, ".*\.(pdf|txt|doc|docx|...)")) ; Adjust file extensions as needed
{
; Extract the file name and path from the title
if (RegExMatch(active_title, ".*\\(.*\.(pdf|txt|doc|docx|...))", matches))
{
file_name := matches1
file_path := matches2
; Combine file name, full path, and copied text
clipboard := file_path . "\" . file_name . "`r`n" . clipboard
}
else
{
MsgBox, No file name or path found in window title.
}
}
else
{
; Not a relevant file, so copy just the text
Send, ^c
}
Return
如果程序在“最近的项目”文件夹中创建打开文件的快捷方式,您可以尝试以下操作: