Autohotkey 自动热键:如何确定文本文件是在emac还是notepad3中打开的
我需要确定一个打开的文本文件的路径和文件名,不管它是在Notepad3还是在Emacs中打开的 对于这两个编辑器,路径和文件名都显示在打开文件的窗口标题中。因此,我可以使用AHK函数Autohotkey 自动热键:如何确定文本文件是在emac还是notepad3中打开的,autohotkey,Autohotkey,我需要确定一个打开的文本文件的路径和文件名,不管它是在Notepad3还是在Emacs中打开的 对于这两个编辑器,路径和文件名都显示在打开文件的窗口标题中。因此,我可以使用AHK函数wingtittle提取窗口标题,然后使用函数SubStr从窗口标题提取路径和文件名 但是,这两个编辑器在窗口标题中显示路径和文件名的方式不同。在Notepad3中,标题格式为[filename][path],而在Emacs(我的配置)中,标题格式为[path][filename] 我希望无论文本文件在哪两个编辑器中
wingtittle
提取窗口标题,然后使用函数SubStr
从窗口标题提取路径和文件名
但是,这两个编辑器在窗口标题中显示路径和文件名的方式不同。在Notepad3中,标题格式为[filename][path],而在Emacs(我的配置)中,标题格式为[path][filename]
我希望无论文本文件在哪两个编辑器中打开,我的代码都是可用的。我想我必须使用某种if语句
我的伪代码如下所示:
::uuu::
; find the window title of the opened txt file
WinGetTitle, windowTitle, A
; determine if text file is opened in Notepad3 or in Emacs
appName = <some function>
; construct file name and file path from window title
if appName = notepad3
fileName := SubStr(windowTitle,3,24)
filePath := SubStr(windowTitle,29,-12)
elseif appName = emacs
fileName := SubStr(windowTitle,-23)
filePath := SubStr(windowTitle,1,-24)
end
; send input to file
SendInput, %windowTitle% {enter}
SendInput, %fileName% {enter}
SendInput, %filePath% {enter}
return
::uuu::
; 查找打开的txt文件的窗口标题
Wingtittle、windowTitle、A
; 确定文本文件是在Notepad3还是在Emacs中打开的
appName=
; 从窗口标题构造文件名和文件路径
如果appName=notepad3
文件名:=SubStr(windowTitle,3,24)
文件路径:=子文件(windowTitle,29,-12)
elseif appName=emacs
文件名:=SubStr(windowTitle,-23)
文件路径:=子文件(windowTitle,1,-24)
结束
; 将输入发送到文件
SendInput,%windowTitle%{enter}
SendInput,%fileName%{enter}
SendInput,%filePath%{enter}
返回
1) 什么AHK函数可用于确定appName
2) 如果可以确定
appName
,我的代码中的if语句应该如何使用正确的AHK语法?我想我找到了一种解决我自己问题的方法:
::uuu::
; find the window title of the opened txt file
WinGetTitle, windowTitle, A
; find the process or app used to open the text file
WinGet, process, ProcessName, A
; construct file name and file path from window title
if (process = "Notepad3.exe")
{
fileName := SubStr(windowTitle,3,24)
filePath := SubStr(windowTitle,29,-12)
}
else if (process = "emacs.exe")
{
fileName := SubStr(windowTitle,-23)
filePath := SubStr(windowTitle,1,-24)
}
; send input to file
SendInput, %windowTitle% {enter}
SendInput, %fileName% {enter}
SendInput, %filePath% {enter}
SendInput, %process% {enter}
return