Home
Download
Screenshots

Wiki
Plugins
Translations
Developers
Donate

Forums/Help
Contact Us

StrokeIt

"Ctrl + mouse click" with classic gesture to open link in new tab

Posted by mr01 
"Ctrl + mouse click" with classic gesture to open link in new tab
February 09, 2011 11:51AM
hi All,
I found here example of ahk script (posted by Cerberus God bless him! ;) )
^!+r::
MouseGetPos, xpos, ypos
If (ypos < 70)
  SendInput ^+{Tab}
else
  {
  SendInput {Browser_Back}
  }
Return

It's really usefull, but my question is, is it possible to create that kind of script witch will allow to get MouseGetPos , xpos, ypos BUT FROM POINT where we start drawing classic gesture and then send to that definite point some keystroke or mouse click???
That above script works only for rocker gesture and it's executed in a point of screen where left mouse button is released (UP)

As we know (in Firefox) we can open link in new foreground or background tab depends on which one of modifier keys we press with mouse click on link.
By default:
"Ctrl + mouse click" opens link in new background tab
"Ctrl + Shift + mouse click" opens in new foreground tab

We can send to firefox one of these combination BUT it will works for link only then when mouse pointer is currently over that link.

These combinations WILL NOT work if we'll use them with one of classic gesture (e.g. left-up, right-down etc.)

So, our experts have any ideas? :)

Best Regards
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 09, 2011 01:24PM
As far as I know, Firefox has its own position aware mouse gesture (plugin?) which is able to do different link operations by dragging the link in different directions. I'd try this as first approach.

My second idea would be (assuming you use StrokeIt Pro) to use Lua script to bring the cursor back to start position (it has functions for this) and send the key + mouse click combo.

Thirdly, the leas convenient but most obvious solution requires two clicks. First a RMB click on the link gives a pop-up where you can select the desired action and confirm it with a LMB click.

Alternatively, most browser open links in background tab using MMB.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 12:53AM
Thanks gemisigo.

I wish I had StrokeIt Pro but it seams that Jeff is completely disappeared - somewhere. God only knows where.... :(
and so using LUA (at least at present) is not an option :(
I thought maybe there is some Autohotkey script which can brings cursor back to desire start position.

One solution which I practiced was creating combination e.g.
1. Send Ctrl_down
2. Delay e.g. max 1000 ms
3. Send Ctrl_up

During that delay we click manually on link

The second clue was combination:
1. Delay e.g. 500 ms
2. Send "ctrl + mouse click"

During that "1/2 sec." delay we manually moves mouse pointer over concrete link and wait for the following action.

Propably, a better but not perfect option is that first one.

Yes, Firefox has owns plugins but firstly we all try to use StrokeIt as much as possible (or with autohotkey) :)

Never the less....
Thanks gemisigo.

Best Regards
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 03:51AM
Well, I tried something but did not succeed :) I created this small snippet for Chrome

#IfWinActive ahk_class Chrome_WidgetWin_0
~RButton::MouseGetPos, xpos, ypos ; saves cursor position when beginning the gesture
!^+b::Send ^{Click %xpos%, %ypos%} ; sends CTRL+LMB click at given position
!^+f::Send +^{lick %xpos%, %ypos%}  ; sends SHIFT+CTRL+LMB click at given position
;!^+n::Send +{Click %xpos%, %ypos%} ; sends SHIFT+LMB click at given position
#IfWinActive

It does work if you rightclick the link first (it stores cursor position, you have to manually dismiss the popup, of course) and then press the hotkey (ALT+SHIFT+CTRL+b for background, ALT+SHIFT+CTRL+f for foreground tab and ALT+SHIFT+CTRL+n for new window)

For some unknown reason it does not work when triggered from StrokeIt with the hotkeys described above. It does click the link but it opens it in current tab as if the modifier keys in the Send command are omitted. I used Up-Left and Up-right gestures to make sure the cursor is not on the link.

I hope Cerberus can shed some light on why this does not work as expected :)
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 09:01AM
Oh yes gemisigo!
This is exactly what I was looking for :)
Thanks!!!
#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos ; saves cursor position when beginning the gesture
!#f::Send ^{Click %xpos%, %ypos%} ; sends CTRL+LMB click at given position
!#b::Send ^+{Click %xpos%, %ypos%}  ; sends SHIFT+CTRL+LMB click at given position
#IfWinActive
I've only removed CTRL and SHIFT from hotkeys and leave ALT and WIN
Of course the perfect solution would be sending mouse click to given position without moving mouse cursor up there BUT it's already works as it should.

Thanks again!

Best Regards

-----------------------
btw
I'm curious, is it possible to modify this script in a way e.g.(something like this)
#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos
If (%xpos%, %ypos% are url link)
  !#f::Send ^{Click %xpos%, %ypos%}
else
  {
  Send ^{TAB}
  }
Return
#IfWinActive
So, in order to executing that gesture has two option
a) open link in new tab
b) switch tabs
depends on place where we start drawing gesture



Edited 1 time(s). Last edit at 02/10/2011 09:34AM by mr01.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 11:04AM
Regarding the first, you could rewrite it like this:

SetDefaultMouseSpeed 0

#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos ; saves cursor position when beginning the gesture
!#f::
MouseGetPos, expos, eypos ; saves cursor position at the end of the gesture
Send ^{Click %xpos%, %ypos%, 1 } ; sends CTRL+LMB click at given position, 1 click, and move instantly
MouseMove %expos%, %eypos%, 0 ; move the mouse back where it was at the end of the gesture
Return
!#b::
MouseGetPos, expos, eypos ; saves cursor position at the end of the gesture
Send ^+{Click %xpos%, %ypos%, 1}  ; sends SHIFT+CTRL+LMB click at given position, , 1 click, and move instantly
MouseMove %expos%, %eypos%, 0 ; move the mouse back where it was at the end of the gesture
Return
#IfWinActive

The mouse cursor movement speed default can be set with SetDefaultMouseSpeed. Since you are using 0 (fastest) you should not even see it moved (or just a flash).

The code above is not checked (no ahk on this machine), may fail, but should eventually work (when fixed :). I leave that up to you ;)

As for the second one (position and link-aware behavior), I don't think it could be achieved easily (if possible at all) but I'll have to do some research first. I'll report back later.

I'll try your version with Win key as shortcut instead of CTRL+SHIFT to see if that was making the code not work in Chrome. Thanks for the update.



Edited 2 time(s). Last edit at 02/10/2011 11:20AM by gemisigo.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 11:38AM
I removed 1 and 0 from
{Click %xpos%, %ypos%, 1, 0}
cause not needed changing those default settings.
Generally works fine :) but I'm just thinkin' which solution is better
a) moves mouse pointer to start position and stays there
or
b) moves mouse pointer to start position and again to end position of gesture

:D

How bloody fast wouldn't it be, I'd rather pick up that first one :)
but it's good to know there're alternatives.

p.s.
If you find out how to get to know if starting point is a url link and then was able to choose what command should be executed, it would be fantastico! :)

Meanwhile...
Best Regards

------------------------
btw
I removed CTRL and SHIFT from main keysrtokes and left ALT and WIN cause there were some problems with executing
^{click......"}
^+{click....}
propably because of they contain those modifier keys and
^+
worked like alone CTRL without SHIFT



Edited 2 time(s). Last edit at 02/10/2011 11:51AM by mr01.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 11:47AM
Check my previous post, please. You might have read it before my second edit so you are missing some parts.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 11:58AM
No, I didn't miss any parts.
But I decided to leave some things as it is - NOT changing them :)
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 12:23PM
And now it happened that I read yours before your second edit :) The part I was referring to is that you cannot use the mouse speed settings with the Click, that is, my edited code did not contain the very same "0" you removed (the "1" may stay, changes nothing since it is the default, I only used it because, I had to provide a third param to have a fourth :)
Never mind, I see you figured out on your own.

The good news is that I might have found a method to create a link-aware script. The bad news is that I still have to check it.

EDIT: Nay, it does not work (well). It selects everything on the text if the stuff under the cursor is not a link. Have to find a different way. Sorry. It may take some time.



Edited 1 time(s). Last edit at 02/10/2011 12:53PM by gemisigo.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 10, 2011 07:32PM
The below is extremely ugly, but it works for me, and the FF interface is so weirdly built that AHK cannot recognise any of its controls. It works by matching a screenshot snippet against the status bar, in order to see whether the cursor is hovering over a link. You might need to enable that if the statusbar doesn't display that in your set-up.
~RButton::MouseGetPos, xpos, ypos
^!Numpad8::                     ;______ this hotkey opens url in new tab if url, else opens new tab
BlockInput, MouseMove           ;______ blocks moving the cursor by hand: probably safest, but not required for the action to work
MouseGetPos, xpos2, ypos2       ;______ end of gesture, we want to go back here in there end, yes it is quite fast
MouseMove, %xpos%, %ypos%, 0    ;______ this is somehow usually faster and safer that just a click on coordinates without a move first
; Sleep 100                     ;______ not needed for me, but could be added for extra reliability
Click, right                    ;______ opens context menu;
                                ;______ for the line below, you need to make a screenshot-snippet of the part of the statusbar that says "http" and save it to file
ImageSearch, Imagex, Imagey, 1, 1, %A_ScreenHeight%, %A_ScreenWidth%, *20 D:\Documenten\FF_Http_statusbar.gif    ;______ checks whether image is visible on screen
Sendinput {Escape}              ;______ closes right-click menu
If ErrorLevel = 0               ;______ if a match is found
{
SendInput, {Shift down}{control down}{LButton}    ;______ only this works for me; "sendinput, !^{click}" does not, for some reason
Sleep 100                                         ;______ even AHK is not always reliable with keystrokes: if it doesn't work on your PC, increase this to, say, 200ms
SendInput, {Shift up}{control up}
}
else
SendInput, ^t                      ;______ opens new empty tab; note that no "}" is required if "else" or "if" includes only one line
MouseMove, %xpos2%, %ypos2%, 0     ;______ moves mouse back to where it was, at the end of the gesture; this happens regardless of if/else conditions
BlockInput, MouseMoveOff           ;______ re-enables the ability to move the cursor by hand
return
You'd need to make separate versions for opening in background tab, etc.

I used to have the same configuration you had, with up = open link in foreground / open blank tab, etc, with FireGestures. Then I dropped that for StrokeIt because it wasn't reliable enough.

But my advice would be to use EasyDragToGo, the Firefox extension: it lets you specify different actions for dragging a link up, down, right, or left; same for dragging a picture. You do it all with the left mouse button, which is even more convenient than the right mouse button. Moreover, my image matching is not compatible with changing computers or changing things about the layout of Firefox, so that it may break if any of those things happen, in which case you'd need to make new screenshot snippets.

For creating a new tab, I just use a different gesture (N). I find that I do not miss the context-sensitive up-gesture, because using a different gesture in a different context is easy to process for the brain. In addition, you do not need to watch where the cursor is at if you want to open a new window, which is especially important when you have a weird page with hidden links behind "white" background, like Google search hits.



Edited 6 time(s). Last edit at 02/10/2011 07:43PM by Cerberus.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 01:19AM
Your script seams to not working for me.
It opens new tab but doesn't work for a link.

I've already checked EasyDragToGo, but I prefer to use other extension "Grab and Drag" which conflicts with it.
"Grab and Drag" allows to navigate on webpage in the same way like in the case of pdf document and I really love it :) and don't want to add one more mouse button to operate e.g. right for StrokeIt, left for Grab and Drag, middle for EasyDragToGo :)
It's too much for me :)
Never mind....

Once I was talked with author of other "mouse gesture for windows" app (brand new, released on december, [url=http://www.justgestures.com/screenshots/]Just Gestures[/url]) and he says that (let me allow quoting him)
Quote

For example even though I might be able to get text under cursor I will never get href link from <a href="url"> click_here </a>. Because GUI expose only "click_here" and in source code is written the link but I don't have an access to it.
So I see it in dark colors :(
BUT I still hope there must be some way to get url link on right click
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 02:46AM
There is, and it's the most obvious one, I wonder why no one noticed :)

Right clicking on a link (be it a direct link or a <a href="url"> click_here </a> type, it does not matter) pops up a menu with the nice little "Copy Link Location" item (letter "a" underscored). That means if you press key "a" next, you'll have the link on the clipboard. It's just a flick of wand in ahk :) to check if the text on the clipboard starts with "http" (or ftp or whatever you want). It works flawlessly, this was the method I tried first. The problem is that if the text under the cursor is not a link then the popup item that owns the hotkey "a" is "Select All" which has clearly the undesired side effect of selecting everything on the page. That's why I wrote "It does not work (well)"
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 06:18AM
It's propably "the most obvious one" BUT I think it's better to stay with sending "Ctrl+click" or "Ctrl+Shift+click"
That method with context menu and "a" needs next:
a) open new tab "ctrl+t"
b) paste and go "ctrl+v" + enter

So back to the ealier method....
For me the only disadvantage are mouse's moves to given (x, y) params.
FUNDAMENTAL question is:

Is it possible to send mouse click to concrete (previously taken) x y params WITHOUT the need to moves mouse cursor up there?

As far as I know, it's propably impracticable :(
or I'm wrong? ;)

So, for me this subject seams to be rather close for now UNTILL someone will figure it out how to technically answer that above question :)

Best Regards
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 08:08AM
No, I guess you misunderstood. You use the context menu and "a" to check if the stuff under the cursor is actually a link and whether to send the click (plus modifier keys) or not, you don't use the text on the clipboard to open the link in a new tab. It is solely for check. But not being a link interferes (selecting all).

To be precise, with built-in ahk functions you have to "move the mouse away". You don't have to move the mouse there (Send {Click ... does that for you). But if you use MouseMove with the position saved at the end of the gesture the cursor will be moved exactly where you left it. Setting SetDefaultMouseSpeed to 0 makes this happen (near) instantly (you can see a flash of the cursor but that's all). Can you tell me why is this not sufficient for you?

You should be able to send mouse click to arbitrary positions using sendmessage/postmessage but it's not that simple as the solution shown here (even if it is not perfect). That's something you have to get info from the net (message id, parameters) and requires some preparations. I would not judge that as worth the effort but you are free to do it. If you choose that path, post your experiences please.



Edited 2 time(s). Last edit at 02/11/2011 08:09AM by gemisigo.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 10:18AM
@Mr01: Hmm, I wonder why my method didn't work for you. Are you sure you made a screenshot of the statusbar, not the address bar? Are you sure you saved the screenshot file correctly? It should look like this: http://img291.imageshack.us/f/ffforegroundtab.gif/
It will of course not look exactly the same for your browser set-up. And of course it could be broken if your Firefox doesn't show the URL in the statusbar when you hover over a link. That is why it is ugly coding. But so far it is the only thing that works at all. If it still doesn't work, perhaps you could add a few Sleep 200 lines in the code?

I can understand that using the middle mouse button is a personal choice. I wasn't using it at all, until I made the switch from Firegestures + StrokeIt to full StrokeIt, because then I needed a good replacement. So I use middle button for Grab and Drag, another extension I could never live without. I actually made the same function for Photoshop because I missed dragging with the middle button. Very simple code btw, and fairly reliable. But of course different people have different needs. I agree wholeheartedly that Firefox is a bad boy for making its interface so inaccessible. The only thing that makes up for that is its awesome extensions.

As Gemisigo said, the problem is not so much that we can't move the cursor back up after the gesture. We've technically used the "move" command, but because it moves at near-infinite speed, you hardly notice it except a quick flash. I agree that its not being required to move at all for a click would have been neater. But it is not the worst of our problems at the moment.

@Gemisigo: Right, I tried that method with the context menu too. Then it seemed necessary to get AHK to act differently based on what was visible in the context menu; but nothing worked, neither ControlGetText nor SearchImage. It appears AHK cannot see any FF menu at all. ImageSearch on the statusbar is the only thing that works.

Personally, I hate the flashing context menus: everything about them says "unreliable" and "ugly coding". I am using actual simulated mouseclicks on the address bar in order to escape Flash focus in FF, because it is the only option—but I am not too happy with it, and it is not 100% reliable: sometimes AHK registers that my action is carried out on the address bar, even though the cursor should have been moved down again and slept 100. Then it does the wrong action, because my action is based on mouse position (x>200 etc). But this is better than being unable to carry out commands at all when watching a Youtube video, ugh. I believe you Chromies don't have this problem?



Edited 1 time(s). Last edit at 02/11/2011 10:20AM by Cerberus.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 10:24AM
Setting SetDefaultMouseSpeed to 0 it's generally a good solution and the end result satisfies me.
BUT for some reason for once from 10 attempts (approximately) it's seams that it's too fast for properly acting cause apart from correct sending e.g. "ctrl+click" to open link in new background tab it happens that this link opens in the current tab simultaneously EVEN you set 1 for single click.
Strange behaviour :)

So I give it a rest and stay with
#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos
!#f::Send ^{Click %xpos%, %ypos%}
!#b::Send ^+{Click %xpos%, %ypos%}
#IfWinActive
After some tests this belove seams to be the closest to the ideal but like I said before sometimes it seams like mouse sends two clicks even is sets to 1
(maybe unnecessarily but I separated mouse move from click)
#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos
!#f::
MouseGetPos, expos, eypos
MouseMove %xpos%, %ypos%, 0
Send ^{Click, 1}
MouseMove %expos%, %eypos%, 0
Return
!#b::
MouseGetPos, expos, eypos
MouseMove %xpos%, %ypos%, 0
Send ^+{Click, 1}
MouseMove %expos%, %eypos%, 0
Return
#IfWinActive

_____________________________________________________
updated: (for Cerberus)
I used your script. Works as it should but I removed lines
Click, right
Sendinput {Escape}
...cause those flashes of context menu were annoying :) and I don't know why you put them (?) :)
#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos
^!Numpad8::
BlockInput, MouseMove
MouseGetPos, xpos2, ypos2
MouseMove, %xpos%, %ypos%, 0
ImageSearch, Imagex, Imagey, 1, 1, %A_ScreenHeight%, %A_ScreenWidth%, *20 D:\http.bmp
If ErrorLevel = 0
{
SendInput, {control down}{LButton}
Sleep 200
SendInput, {control up}
}
else
SendInput, ^t
MouseMove, %xpos2%, %ypos2%, 0 
BlockInput, MouseMoveOff 
return
#IfWinActive

Best Regards



Edited 6 time(s). Last edit at 02/11/2011 02:01PM by mr01.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 03:52PM
Haha, wow, those lines are stupid indeed. They must have been left-overs from an earlier attempt, in which I tried to detect an image in the context menu (which failed). I can't believe I didn't notice them when I posted this code. Please pretend I never put them there. Without those lines, the effect actually doesn't look so bad. (I still prefer Easy Drag To Go, but OK.)
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 11, 2011 04:16PM
Well, I think this thread contains some very useful tips and tricks for future scripts.

By the way, mr01, if you're interested in the Pro version, besides Lua scripts it also has Mouse Click command the home version lacks. The Mouse Click command allows you to send Left/Right/Middle clicks with button as up/down/click/doubleclick allowing the click to happen at gesture start/end/arbitrary position. Having two Send Keys command
[SHIFT_DOWN][CTRL_DOWN]
and
[SHIFT_UP][CTRL_UP]
enclosing the Mouse Click command the result is just what you wanted. I tested this a few times (though less than 20) and it seems to be reliable (at least in Chrome). This method still does not distinguish links but I'll dig into it if there anything we could do in Lua to find a solution. Perhaps it can be "translated" to ahk too.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 12, 2011 02:59PM
UPDATED: Second ver.
One keystroke for StrokeIt, 4 gestures
Resault: 8 actions


I've played around a little bit and created this script.
First of all you need to create only one keystroke for StrokeIt "Alt + Win + F" and add 4 gestures for it:

up /
(Open link in new foreground tab) or (Next Tab)

up \
(Open link in new background tab) or (Previous Tab)

down /
(Save the link) or (Close Tab and Focus Left Tab)

down \
(Open link in new window) or (Close Tab and Focus Right Tab)

#IfWinActive ahk_class MozillaWindowClass
~RButton::MouseGetPos, xpos, ypos
!#f::
MouseGetPos, expos, eypos
BlockInput, MouseMove
ImageSearch, Imagex, Imagey, 1, 1, %A_ScreenHeight%, %A_ScreenWidth%, *20 D:\http.bmp
If ErrorLevel = 0
	{
	if (xpos < expos)
		{
		if (ypos > eypos)
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send ^+{Click, 1}
			}
		else
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send +{Click, 1}
			}
		}
	else
		{
		if (ypos > eypos)
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send ^{Click, 1}
			}
		else
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send !{Click, 1}
			}
		}
	}
else
	{
	if (xpos < expos)
		{
		if (ypos > eypos)
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send ^{PgDn}
			}
		else
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send ^w
			}
		}
	else
		{
		if (ypos > eypos)
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send ^{PgUp}
			}
		else
			{
			MouseMove %xpos%, %ypos%, 0
			Sleep 100
			Send {ctrl down}{shift down}{PgUp}{shift up}w{ctrl up}
			}
		}
	}
MouseMove %expos%, %eypos%, 0
BlockInput, MouseMoveOff 
Return
#IfWinActive
It uses that technigue (suggested by Cerberus) with checking if LINK on the basis of previously captured image of http



Edited 2 time(s). Last edit at 02/13/2011 12:58AM by mr01.
Re: "Ctrl + mouse click" with classic gesture to open link in new tab
February 12, 2011 03:08PM
Clever ;)
Author:

Your Email:


Subject:


Spam prevention:
Please, solve the mathematical question and enter the answer in the input field below. This is for blocking bots that try to post this form automatically.
Question: how much is 1 plus 18?
Message: