Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

IE: Open Hyperlink in New Window With Middle Mouse Button


  • Please log in to reply
12 replies to this topic
shomizu9
  • Members
  • 4 posts
  • Last active: Aug 15 2004 08:53 PM
  • Joined: 29 Jul 2004
First:

Thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you thank you for creating autohotkey :D

That out of the way:

A friend of mine wanted to be able to open hyperlinks on a webpage in a separate window (like you would normally do with shift + left click) in Internet Exploder. I won't go into all the other smooth and l337 options my friend could have gone with (using Firefox for example lol) instead of using IE here, but let's just say I looked around for sometime for some info on how to change what a mouse button can do using the Mouse control panel, the windows registry, how to map keyboard shortcuts to mouse buttons, etc before finding autohotkey

What I came up with is simple, and will probably be poked fun at since it only does *one* thing - but that's ok, because it worked for what my friend wanted. I'm sure this is hardly original, but I was unable to find anything searching the forum that would make this plagiarism - please feel free to flame me if you've already submitted this :p

MButton::
Send, {SHIFTDOWN}
MouseClick, left, , , 1, , 
Send, {SHIFTUP}

As I want to learn more about autohotkey and expand on what I can do with it, I appreciate any comments at all.

I've only tested this on:
- Windows 2000
- Internet Exploder 6


Peace.

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
A slight improvement is that the line "MouseClick, left, , , 1, , " can be simplified to "MouseClick, left" since 1 is the default number of times to click.

Sometimes the simplest macros are the best ones. That's a nice one and I've often wanted such a feature myself. Maybe I'll find a way to apply it with a hotkey rather than sacrificing the middle mouse button.

One way to make the middle mouse button multipurpose is the following:
MButton::
IfWinActive, ahk_class IEFrame  ; Internet Explorer
{
     Send, {SHIFTDOWN} 
     MouseClick, left
     Send, {SHIFTUP} 
}
else IfWinActive some other window
{
... take some other commonly used action appropriate to that window ...
}
else  ; Do default
     MouseClick, middle  ; Send a plain middle button click through.
return
One related feature comes to mind: Window groups. Since your friend is not the only one who likes to have multiple MSIE windows open simultaneously, I find the following very useful:
; In the autoexecute section at the top of the script: 
GroupAdd, MSIE, ahk_class IEFrame ; Add only Internet Explorer windows to this group.
return ; End of autoexecute section.

; Assign a hotkey to activate this group, which traverses
; through all open MSIE windows, one at a time (i.e. each
; press of the hotkey).
Numpad1::GroupActivate, MSIE, r
I created window groups as a customizable sort of "alt tab" that selectively activates only the windows of your choice. That way, you can have multiple flavors of alt-tab, each of which visits only certain windows (or types of windows).

shomizu9
  • Members
  • 4 posts
  • Last active: Aug 15 2004 08:53 PM
  • Joined: 29 Jul 2004
pure genius man, pure genius

:D

thanks for posting the "on/off-switch" for using the middle button in IE

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004
Still allows you to autoscroll-


MButton::

StatusBarGetText, OutputVar,, ahk_class IEFrame

if OutputVar<>done
{
gosub, new_window
}
else
{
MouseClick, middle
return
}

if OutputVar<>
{
gosub, new_window
}
else
{
MouseClick, middle
return
}

return

new_window:

IfWinActive, ahk_class IEFrame  ; Internet Explorer
{
     Send, {SHIFTDOWN}
     MouseClick, left
     Send, {SHIFTUP}
}

return



shomizu9
  • Members
  • 4 posts
  • Last active: Aug 15 2004 08:53 PM
  • Joined: 29 Jul 2004
Jon,

when using your script, I notice that when clicking the middle button again (normally stops the scroll function), the scroll function stays on. you can disable it again by clicking the left mouse button of course, but in terms of examining the hows and whys of AHK, why would your particular script do this?

what would be put in the script to get the scroll function to stop normally, i.e. by clicking the middle button again?

thanks

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
It's a great idea of Jon's to use MSIE's status bar to detect whether the mouse is hovering over a link. However, I can't say I fully understand the script, namely the part that starts with "if OutputVar<>". It doesn't seem to have any purpose and might instead cause unwanted behavior. But maybe it's just too early in the morning and I can't see it.

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004

can't say I fully understand the script, namely the part that starts with "if OutputVar<>".


I noticed that when using internet explorer the status bar would sometimes be blank instead of saying "done".

when using your script, I notice that when clicking the middle button again (normally stops the scroll function), the scroll function stays on. you can disable it again by clicking the left mouse button of course, but in terms of examining the hows and whys of AHK, why would your particular script do this?

what would be put in the script to get the scroll function to stop normally, i.e. by clicking the middle button again?


I didn't have that problem. You might want to check the status bar text when you click the second time though. If the status bar text doesn't say "done" or isn't blank then it won't send a middle mouse click.

shomizu9
  • Members
  • 4 posts
  • Last active: Aug 15 2004 08:53 PM
  • Joined: 29 Jul 2004
ahhh, this makes sense after reading your whole post (response to Chris' post as well as response to mine)

thanks again

Jon
  • Members
  • 349 posts
  • Last active: Aug 30 2011 08:35 PM
  • Joined: 28 Apr 2004

However, I can't say I fully understand the script, namely the part that starts with "if OutputVar<>". It doesn't seem to have any purpose and might instead cause unwanted behavior.


I see what you mean now, it was a bit messy. I've changed the code below. It should work better now.


MButton::

StatusBarGetText, OutputVar,, ahk_class IEFrame

ifequal, OutputVar, done
{
MouseClick, middle
exit
}

ifequal, OutputVar,
{
MouseClick, middle
exit
}

IfWinActive, ahk_class IEFrame
{
     Send, {SHIFTDOWN}
     MouseClick, left
     Send, {SHIFTUP}
}

exit


Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
Now this I understand. Thanks.

BoBo
  • Guests
  • Last active:
  • Joined: --
I guess you've realized it. Additionaly to the "Done" at the IE statusbar the animated icon, top right, is changing (aka stops) if a page has finished loading.

Another option.
I've used a "pixel changed color" routine to detect the bottom left pixel at the D from "Done". It's working fine since ages 8)

Well, that was before Chris offered AHK and its StatusBarGetText command 8) ...

Chris
  • Administrators
  • 10727 posts
  • Last active:
  • Joined: 02 Mar 2004
I'm using the following variation of Jon's and shomizu9's ideas. This one opens the link in a new browser window, the difference being that it switches back to the original window afterward (I know other browsers can do this, but it seems to be a feature missing from MSIE). This is useful for opening a series of links or pictures for later review.

How to use: Click the middle mouse button on a link to open the link in a new background window. The middle mouse button will continue to function normally for all non-MSIE windows, and even in MSIE when the mouse isn't hovering over a link.

MButton::
IfWinActive ahk_class IEFrame
{
	StatusBarGetText, bar_text
	if bar_text <> done
		if bar_text <>
		{
			Send, {SHIFTDOWN}
			MouseClick, left
			Send, {SHIFTUP}
			WinWaitNotActive  ; The new window has appeared.
			Sleep 100         ; Helps reliability of next line.
			WinActivate       ; Go back to the old window.
			return
		}
}
; Otherwise, do the normal MButton action:
MouseClick, middle
return

Thanks to Jon and shomizu9 for the original ideas.

Edit: Added "Sleep 100" to improve reliability.

badmojo
  • Members
  • 204 posts
  • Last active: Jul 23 2014 01:39 AM
  • Joined: 11 Nov 2005
Chris: how can i adapt this script to work in Maxthon or IE7? because it doesn't work with tabbed browsers reliably as they work once and then don't work until some time passes in-between. i tried changing the sleep timer but to no avail.