AutoHotkey Community

It is currently May 26th, 2012, 8:42 pm

All times are UTC [ DST ]




Post new topic Reply to topic  [ 7 posts ] 
Author Message
PostPosted: August 26th, 2009, 12:25 pm 
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?


Report this post
Top
  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 12:35 pm 
Offline

Joined: May 17th, 2007, 12:07 pm
Posts: 1004
Location: Germany - Deutschland
instead of copying the http to clipboard I would use ControlGetText and ControlSend to the address-bar.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 12:36 pm 
Offline
User avatar

Joined: August 30th, 2005, 8:43 pm
Posts: 8666
Location: Salem, MA
you can use StringSplit and SplitPath for more reliable editing of the URL.

_________________
Image
(Common Answers) - New Tutorials Forum - Humongous FAQ


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 26th, 2009, 12:38 pm 
try adding a sleep, 250 after send !d


Report this post
Top
  
Reply with quote  
PostPosted: August 28th, 2009, 3:18 pm 
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


Report this post
Top
  
Reply with quote  
PostPosted: August 28th, 2009, 3:44 pm 
Offline
User avatar

Joined: March 19th, 2008, 12:43 am
Posts: 5480
Location: the tunnel(?=light)
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

_________________
Image
Try Quick Search for Autohotkey or see the tutorial for newbies.


Report this post
Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: August 29th, 2009, 9:34 pm 
Offline

Joined: March 27th, 2009, 1:00 am
Posts: 26
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!


Report this post
Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC [ DST ]


Who is online

Users browsing this forum: BrandonHotkey, Google Feedfetcher, joetazz, Leef_me, Mickers, tidbit, tomoe_uehara and 63 guests


You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group