Browser 如何使用自动热键脚本获取当前浏览器URL?
我正在寻找一种在AutoHotkey中将当前访问的url放入变量的方法 这个AHK的目标是追踪我在一天中所做的事情,以便更好地记录我的工作时间。我有另一个系统,我用它来计时我的工作,但有时我忘记了使用它,当我被跟踪Browser 如何使用自动热键脚本获取当前浏览器URL?,browser,autohotkey,Browser,Autohotkey,我正在寻找一种在AutoHotkey中将当前访问的url放入变量的方法 这个AHK的目标是追踪我在一天中所做的事情,以便更好地记录我的工作时间。我有另一个系统,我用它来计时我的工作,但有时我忘记了使用它,当我被跟踪 loop { ; Get current Window ID & Name WinGet, active_id, ID, A WinGet, process_name, ProcessName, A ; Only do anything if
loop
{
; Get current Window ID & Name
WinGet, active_id, ID, A
WinGet, process_name, ProcessName, A
; Only do anything if any other windows was activated
if(active_id = PrevActiveId)
{
; Do nothing
}
else
{
; Format the time-stamp.
current=%A_DD%/%A_MM%/%A_YYYY%, %A_Hour%:%A_Min%
; Write this data to the log.txt file.
fileappend, %current% - %process_name%`n, log.txt
; Get the URL if process_name = "chrome.exe"
if(process_name = "chrome.exe")
{
; Put URL in log file
; fileappend, %current% - %current_url%`n, log.txt
}
}
PrevActiveId = %active_id%
Sleep, 100
}
或者您可以使用F6
当按F6键时,大多数浏览器都会进入地址栏并为您选择整个URL
那就是复制粘贴的问题了
对于较新的Firefox版本,它的Ctrl+L组合键仍然有效
为此,您可以选中窗口标题。对于Chrome,获取控件Chrome_OmniboxView1的文本,即omnibox(对于当前版本的Chrome,21.0.1180.83) 此代码将omnibox的内容放入变量omniboxContents中:
ControlGetText omniboxContents, Chrome_OmniboxView1, Chrome
请注意,omniboxContents不一定包含正确的URL,因为如果URL以“http://”开头,则“http://”将被忽略。因此,与其说http://www.google.com你会看到“www.google.com”,严格来说,这不是一个正确的URL。这仅仅是因为Chrome在Omnibox中以这种方式显示地址。您需要添加额外的代码才能从omnibox的内容中获得正确的URL。我使用的所有浏览器都支持Alt+D来聚焦和选择URL。下面是我的AHK脚本,通过按Ctrl+Shift+D复制Google Chrome、Firefox和Internet Explorer中的当前选项卡
一种干净的方法:
GroupAdd, WebBrowsers, ahk_class MozillaWindowClass
GroupAdd, WebBrowsers, ahk_class IEFrame
GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_0
GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_1
GroupAdd, WebBrowsers, ahk_class OperaWindowClass
GroupAdd, WebBrowsers, ahk_class {1C03B488-D53B-4a81-97F8-754559640193}
; etc.
#IfWinActive, ahk_group WebBrowsers
{
^+d::
; [Instructions...]
return
}#If
通过直接检查构成浏览器窗口的实际组件,也可以在不依赖剪贴板的情况下执行此操作。更多信息:。此方法更加有效,但依赖于使用操作系统API。您可以使用Alt+D快捷方式激活地址栏,然后使用Ctrl+C快捷方式复制url
解决了这个问题,但“声誉低于100的用户在提问后8小时内无法回答他们自己的问题。您可以在5小时内自行回答。”因此,将在5小时后报告-(5小时后回来发布你的答案是个好主意。它可以帮助其他人:)这不是一个好把戏。我正在干扰用户浏览器,用户可能会认为这是一个黑客短的东西。我建议使用Alt+D而不是F6。F6键切换焦点,这意味着如果URL栏已经处于焦点,您可能会意外地取消选中它。这看起来已经过时了。
GroupAdd, WebBrowsers, ahk_class MozillaWindowClass
GroupAdd, WebBrowsers, ahk_class IEFrame
GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_0
GroupAdd, WebBrowsers, ahk_class Chrome_WidgetWin_1
GroupAdd, WebBrowsers, ahk_class OperaWindowClass
GroupAdd, WebBrowsers, ahk_class {1C03B488-D53B-4a81-97F8-754559640193}
; etc.
#IfWinActive, ahk_group WebBrowsers
{
^+d::
; [Instructions...]
return
}#If
F1::
{
Send, !d
Sleep 50
Send, ^c
Sleep 50
Return
}