以下代码在按下 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
答案1
如果程序在“最近的项目”文件夹中创建了已打开文件的快捷方式,您可以尝试以下操作:
#NoEnv
#SingleInstance force
SetTitleMatchMode, 2
; Get the path of the recent items folder
RegRead, Recent, HKCU, Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders, Recent
RETURN ; === end of auto-execute section ===
#IfWinActive - Drawboard PDF ahk_class ApplicationFrameWindow
; Press F1 to get the name and path of the pdf file opened in the active DrawboardPDF window:
F1::
WinGetActiveTitle, active_title
active_title := StrSplit(active_title," - Drawboard PDF").1
If FileExist(Recent "\" active_title ".lnk")
{
FileGetShortcut, %Recent%\%active_title%.lnk, path
MsgBox, Name = "%active_title%"`nPath = "%path%"
}
else
MsgBox, path not found
return
#IfWinActive ; turn off context sensitivity