AutoHotkey Homepage AutoHotkey Community
Let's help each other out
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to get and manipulate URL in internet software

 
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help
View previous topic :: View next topic  
Author Message
andrewafresh
Guest





PostPosted: Wed Aug 26, 2009 11:25 am    Post subject: How to get and manipulate URL in internet software Reply with quote

I’m trying to create a hotkey that I can use when viewing the internet to go up one level e.g. if I am viewing a page with this address:
http://www.me.com/level1/level2
the script will take me to:
http://www.me.com/level1

This is the script:

F1::
Clipboard = ;empty the clipboard
send !d ; move to the address line
send ^c ;copy the URL to clipboard
clipwait
StringGetPos, SlashPos, Clipboard, /, R1 ; find out where the last slash resides in URL
if SlashPos = -1 ;if no slash, exit
return
LeftChars := SlashPos - 1 ; subtract one from the slash position
stringleft, NewUrl, Clipboard, %LeftChars% ;copy everything before the slash into NewUrl
send %NewUrl%
sleep 300
send {enter}
return

The problems are:
1) it usually does not copy the URL to the clipboard- it just waits and waits till I press Ctrl+C myself
2) the variable NewUrl often starts tp: and not http:

Any ideas?
Back to top
aaffe



Joined: 17 May 2007
Posts: 1002
Location: Germany - Deutschland

PostPosted: Wed Aug 26, 2009 11:35 am    Post subject: Reply with quote

instead of copying the http to clipboard I would use ControlGetText and ControlSend to the address-bar.
Back to top
View user's profile Send private message
engunneer



Joined: 30 Aug 2005
Posts: 8255
Location: Maywood, IL

PostPosted: Wed Aug 26, 2009 11:36 am    Post subject: Reply with quote

you can use StringSplit and SplitPath for more reliable editing of the URL.
_________________

(Common Answers)
Back to top
View user's profile Send private message Visit poster's website
Guest






PostPosted: Wed Aug 26, 2009 11:38 am    Post subject: Reply with quote

try adding a sleep, 250 after send !d
Back to top
andrewafresh
Guest





PostPosted: Fri Aug 28, 2009 2:18 pm    Post subject: The final code that seems to work Reply with quote

Many thanks for all your replies. For the record, this is the code which I have got working (in Internet Explorer 7):

^d::
controlgettext, oldurl, edit1, A
;msgbox %oldUrl%
stringright, LastChar, oldurl, 1
if LastChar = / ; if URL ends in / remove the /
StringTrimRight, oldurl, oldurl, 1
StringGetPos, SlashPos, oldUrl, /, R1 ; find out where the last slash resides in URL
if SlashPos = -1 ;if no slash, exit
return
;msgbox %SlashPos%
LeftChars := SlashPos - 0 ; subtract one from the slash position
;msgbox %LeftChars%
stringleft, NewUrl, oldUrl, %LeftChars% ;copy everythnig before the slash into NewUrl
;msgbox %NewUrl%
send !d ; move to the address line
sleep 300
send %NewUrl%
sleep 300
send {enter}
;ControlSetText, Edit1, %NewUrl%, A
return
Back to top
sinkfaze



Joined: 18 Mar 2008
Posts: 5044
Location: the tunnel(?=light)

PostPosted: Fri Aug 28, 2009 2:44 pm    Post subject: Re: The final code that seems to work Reply with quote

You should be able to bump the reliability by sending the finished product to the clipboard and pasting it:

Code:
^d::
controlgettext, oldurl, edit1, A
stringright, LastChar, oldurl, 1
if LastChar = / ; if URL ends in / remove the /
    StringTrimRight, oldurl, oldurl, 1
StringGetPos, SlashPos, oldUrl, /, R1 ; find out where the last slash resides in URL
if SlashPos = -1 ;if no slash, exit
   return
LeftChars := SlashPos - 0 ; subtract one from the slash position
StringLeft, Clipboard, oldUrl, %LeftChars%
send !d ; move to the address line
sleep 300
send ^v
sleep 300
send {enter}
return


By the way if you want to use ControlSetText to send the data to the address bar you'll have to use a ControlSend command to activate the cursor then send ENTER. This is what I typically use:

Code:
ControlSetText, Edit1, %NewUrl%, A
ControlSend, Edit1, {SHIFTDOWN}{END}{SHIFTUP}{ENTER}, A

_________________
Try Quick Search for Autohotkey or see the tutorial for newbies.
Back to top
View user's profile Send private message Send e-mail
Astrognaw



Joined: 27 Mar 2009
Posts: 26

PostPosted: Sat Aug 29, 2009 8:34 pm    Post subject: Reply with quote

Code:
#include COM.ahk
#include GetWebBrowser.ahk
#NoEnv
^d::
Com_Init()
pie := GetWebBrowser()
gUrl := COM_Invoke(pie, "LocationURL")
StringTrimRight, gUrl, gUrl, 1
StringGetPos, SlashPos, gUrl, /, R1
if SlashPos between 6 and 7
   return
SplitPath, gUrl,, gUrl
Com_Invoke(pie, "Navigate", gUrl)
Com_Term()


Works for me in IE7. Uses COM and Sean's GetWebBrowser function.
Edit: made less bad.
Edit for explanation:
Sean's COM is here: http://www.autohotkey.com/forum/viewtopic.php?t=22923
Sean's getwebbrowser function is this:

Code:


GetWebBrowser()
{
   ControlGet, hIESvr, hWnd, , Internet Explorer_Server1, ahk_class IEFrame
   If Not   hIESvr
      Return
   DllCall("SendMessageTimeout", "Uint", hIESvr, "Uint", DllCall("RegisterWindowMessage", "str", "WM_HTML_GETOBJECT"), "Uint", 0, "Uint", 0, "Uint", 2, "Uint", 1000, "UintP", lResult)
   DllCall("oleacc\ObjectFromLresult", "Uint", lResult, "Uint", COM_GUID4String(IID_IHTMLDocument2,"{332C4425-26CB-11D0-B483-00C04FD90119}"), "int", 0, "UintP", pdoc)
   IID_IWebBrowserApp := "{0002DF05-0000-0000-C000-000000000046}"
   pweb := COM_QueryService(pdoc,IID_IWebBrowserApp,IID_IWebBrowserApp)
   COM_Release(pdoc)
   Return   pweb
}

(which i have saved to its own ahk file)

Good luck!
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    AutoHotkey Community Forum Index -> Ask for Help All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum


Powered by phpBB © 2001, 2005 phpBB Group