AutoHotkey纯命令获取Chrome等浏览器的当前网址
生活随笔
收集整理的這篇文章主要介紹了
AutoHotkey纯命令获取Chrome等浏览器的当前网址
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
網上大部分都是模擬手工操作(激活地址欄并復制)的方式獲取,從論壇里找到了純命令的方式,并已轉成AutoHotkey v2版本。
是通過瀏覽器的class類來獲取的,相信用AutoHotkey的人對此不陌生
來源:https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702
hyf_getUrlFromBrowser(cls:="Chrome_WidgetWin_1") {reg := "i)^(Chrome_WidgetWin_1|ApplicationFrameWindow|Chrome_WidgetWin_0|Maxthon3Cls_MainFrm|MozillaWindowClass|Slimjet_WidgetWin_1)$"if (cls ~= reg)return hyf_getUrlByACC(cls)elsereturn hyf_getUrlByDDE(cls){ ;通過Surfingkeys獲取網址,通過剪切板傳輸clipboard := ""send("{alt down}c{alt up}")ClipWait(1)u := clipboard}return u }; https://www.autohotkey.com/boards/viewtopic.php?f=6&t=3702 hyf_getUrlByACC(cls:="Chrome_WidgetWin_1") {accAddressBar := GetAddressBar(Acc_ObjectFromWindow(WinGetID("ahk_class " . cls), 0))TrysURL := accAddressBar.accValue(0)If !strlen(sURL) ;Chrome可能用不到{arrWin := WinGetList("ahk_class " . cls) ; In case of a nested browser window as in the old CoolNovo (TO DO: check if still needed)If (arrWin.length() > 1){accAddressBar := GetAddressBar(Acc_ObjectFromWindow(arrWin[2], 0))TrysURL := accAddressBar.accValue(0)}}If ((sURL != "") && (substr(sURL,1,4) != "http")) ; Modern browsers omit "http://"sURL := "http://" . sURLReturn sURLGetAddressBar(accObj){if !IsObject(accObj)returnIf (accObj.accRole(0) = 42){if (accObj.accValue(0).isUrl() || ("http://" . accObj.accValue(0)).isUrl())Return accObj}else{Try{For _, accChild in Acc_Children(accObj){accAddressBar := func(A_ThisFunc).call(accChild)If IsObject(accAddressBar)Return accAddressBar}}}} }hyf_getUrlByDDE(cls) {sServer := WinGetProcessName("ahk_class " . cls)sSearch := substr(sSearch, 1, strlen(sSearch)-4)iCodePage := 0x04B0 ; 0x04B0 = CP_WINUNICODE, 0x03EC = CP_WINANSIdllcall("DdeInitialize", "uptrp",idInst, "uint",0, "uint",0, "uint",0)hServer := dllcall("DdeCreateStringHandle", "uptr",idInst, "str",sServer, "int",iCodePage)hTopic := dllcall("DdeCreateStringHandle", "uptr",idInst, "str","WWW_GetWindowInfo", "int",iCodePage)hItem := dllcall("DdeCreateStringHandle", "uptr",idInst, "str","0xFFFFFFFF", "int",iCodePage)hConv := dllcall("DdeConnect", "uptr",idInst, "uptr",hServer, "uptr",hTopic, "uint",0)hData := dllcall("DdeClientTransaction", "uint",0, "uint",0, "uptr",hConv, "uptr",hItem, "uint",1, "uint",0x20B0, "uint",10000, "UPtrP",nResult) ; 0x20B0 = XTYP_REQUEST, 10000 = 10s timeoutsData := dllcall("DdeAccessData", "uint",hData, "uint",0, "str")dllcall("DdeFreeStringHandle", "uptr",idInst, "uptr",hServer)dllcall("DdeFreeStringHandle", "uptr",idInst, "uptr",hTopic)dllcall("DdeFreeStringHandle", "uptr",idInst, "uptr",hItem)dllcall("DdeUnaccessData", "uptr",hData)dllcall("DdeFreeDataHandle", "uptr",hData)dllcall("DdeDisconnect", "uptr",hConv)dllcall("DdeUninitialize", "uptr",idInst)csvWindowInfo := StrGet(&sData, "CP0")return StrSplit(csvWindowInfo, '"')[2] }
轉載于:https://www.cnblogs.com/hyaray/p/11212846.html
與50位技術專家面對面20年技術見證,附贈技術全景圖總結
以上是生活随笔為你收集整理的AutoHotkey纯命令获取Chrome等浏览器的当前网址的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 开发时对业务技术框架的理解
- 下一篇: step3 . day1 数据结构之线性