且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用 AutoHotKey 脚本获取当前浏览器 URL?

更新时间:2023-10-27 13:08:40

我用过的所有浏览器都支持 Alt+D 来聚焦和选择 url.这是我的 AHK 脚本,通过按 Ctrl+Shift+D..

All browsers that I've used support Alt+D to focus and select the url. Here are my AHK scripts that duplicates the current tab in Google Chrome, Firefox, and Internet Explorer by pressing Ctrl+Shift+D..

#IfWinActive ahk_class MozillaUIWindowClass ; Mozilla Firefox 3.x
   ^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive

#IfWinActive ahk_class MozillaWindowClass ; Firefox 4, 5, 6, 7, 8+ (?)
   ^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive

#IfWinActive ahk_class Chrome_WidgetWin_1 ; Chromium and Chrome 19+
   ^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive

#IfWinActive ahk_class Chrome_WidgetWin_1 ; Chrome 18 and less
   ^+d::GenericDuplicateTab() ; (Control+Shift+D)
#IfWinActive

#IfWinActive ahk_class IEFrame
   ^+d::InternetExplorerDuplicateTab() ; (Control+Shift+D)
#IfWinActive

GenericDuplicateTab()
{
   ; Wait for both Control and Shift to be released.
   KeyWait Control
   KeyWait Shift

   BackupClipbrd := Clipboard
   Sleep 50

   Send !d ; Select the url textbox
   Sleep 150

   Send ^x ; Copy the url
   ClipWait 0.1
   If ERRORLEVEL
   {
    Clipboard := BackupClipbrd
    Return
   }

   Send ^t ; Open a new tab
   Sleep 50

   Send ^v ; Paste the url into the new tab's url textbox
   Sleep 50
   Send {Enter}

   Clipboard := BackupClipbrd
}

InternetExplorerDuplicateTab()
{
   ; Wait for both Control and Shift to be released.
   KeyWait Control
   KeyWait Shift

   Send ^k ; Call IE's shortcut to duplicate tab (Control+K)
   Sleep 100

   Send ^{TAB} ; Switch to that tab
}