Author |
Topic |
|
SomeGuy12
20 Posts |
Posted - 07/18/2012 : 16:44:56
|
I went back to S+ since the text choppyness didn't go away either way :P.
In Mouse gestures Redox and Firegestures of Firefox you could/can do a single gesture for a hybrid command: Open new tab, if it was gestured on a link then open that link in a new tab.
This is the script for Firegestures which of course needs Firegestures to be installed in order to work: "try { FireGestures._performAction(event, "FireGestures:OpenLinkInFgTab"); } catch (ex) { document.getElementById("cmd_newNavigatorTab").doCommand(); }"
Since the pre made code for opening a link in a new tab/window was for Chrome and didn't work in Firefox, i then use this to open a link in a new tab: acMouseClick(gsx, gsy, 1, 1, 1)acMouseMove(gex, gey)
Is there a way to make a code in S+ for doing what Firegestures does? meaning opening a link in a new tab, or simply open a new tab if the gesture wasn't on a link. |
|
Rob
USA
2615 Posts |
Posted - 07/18/2012 : 17:42:59
|
Unfortunately not, since there's no way via the Windows API to detect what's below the mouse to that level of granularity (Firefox owns that responsibility, Windows just says here's where the mouse was clicked).
I really hate constantly failing to help you =P
I would make a simple modifier action pair.
For example, on my system I use Chrome. I have two actions, one for opening a link in a new tab (no gesture, just clicking the stroke button and Left mouse button, set to check modifier after stroke button down) and another which opens a new tab (same combo of no gesture and Left modifier, but checks at time of stroke button down). This way, it's a simple change in when the Left modifier is pressed, before for a blank new tab, after for open link in new tab. |
|
|
SomeGuy12
20 Posts |
Posted - 07/18/2012 : 19:07:37
|
Ok i found an Autohotkey script which with a key detects if the mouse cursor is over a link or not, and sends the keystrokes for opening a new tab if not over a link and for opening the link below the cursor in a new tab if the cursor is over a link. I put the middle mouse button as the button to trigger it:
mbutton:: { if(A_Cursor = "Unknown") { Send {MButton} } else { MouseGetPos, , , , ctrl if(ctrl = "MozillaWindowClass1") Send {MButton} else Send ^{t} } return }
Thus that code is always on and changes the behavior of middle mouse button in Firefox. It does the job as far as middle mouse button is concerned. But it won't work with S+.
I put this code for S+: acMouseClick(gsx, gsy, 1, 1, 1)acMouseMove(gex, gey) which should do a middle click on the start of the gesture position? It opens a new tab if not over a link but it won't open a link in a new tab, just opens a new link if over a link or not. What am i doing wrong here?
And also, is there any way to send a keystroke instead of a mouse click at a certain mouse position? |
Edited by - SomeGuy12 on 07/18/2012 19:08:44 |
|
|
Rob
USA
2615 Posts |
Posted - 07/18/2012 : 19:48:26
|
I'll be back home in a few hours and will look a bit deeper to see if there's something better I can come up with.
As far as the AHK script goes, I'm not sure of its internals but I'm suspicious of its nature as on the surface it would seem it merely looks at whether the mouse is over the browser (HTML) area or not..but I need to investigate further. Also, I don't know whether AHK processes injected mouse events vs. physical ones. S+ sends a synthesized mouse click and AHK might only process a physical mouse click.
I'll look into it more and let you know. |
|
|
SomeGuy12
20 Posts |
Posted - 07/18/2012 : 20:12:05
|
Well i made it work by doing this:
1. Having this AHK script on at all times: #IfWinActive ahk_class MozillaWindowClass #y:: ; Win+y or some other key combo. { if(A_Cursor = "Unknown") { Send {MButton} } else { Send ^{t} } return }
2. Having a gesture in S+ do this: acMouseMove(gsx, gsy) acSendWinDown()acSendKeys("{DELAY=50}y")acSendWinUp() acMouseMove(gex, gey)
So now it works perfectly, except for the minor detail of the mouse cursor moving back and forth, which is of course inconsequential. It does miss sometimes, as in the mouse move command doesn't fire in 1 out of 15 strokes. |
Edited by - SomeGuy12 on 07/18/2012 20:13:18 |
|
|
Rob
USA
2615 Posts |
Posted - 07/18/2012 : 20:43:20
|
You may want to try acConsumePhysicalInput(1) at the start of your script and acConsumePhysicalInput(0) at the end of your script as a slight mouse movement while the action is firing can cause the positioning to be off.
Do NOT forget the acConsumePhysicalInput(0) at the end or you won't be able to use the mouse or keyboard! |
|
|
Rob
USA
2615 Posts |
Posted - 07/18/2012 : 20:45:10
|
That's interesting though, it's checking the mouse cursor type...not a bad idea. I may have a much better solution for you after I get home :-) |
|
|
Rob
USA
2615 Posts |
Posted - 07/18/2012 : 22:39:13
|
Ok, it's not as super-quick as I'd thought, but I still believe I can either come up with an alien script, or possibly a new action function to get the current mouse cursor style...just make take a little bit. |
|
|
SomeGuy12
20 Posts |
Posted - 07/18/2012 : 22:53:25
|
The acConsumePhysicalInput(1) at the start and acConsumePhysicalInput(0) at the end of the script stopped the script from opening a link in a new tab.
Ye if you did the mouse cursor recognition thing in S+ then the random misfiring due to mouse movement would vanish i suppose, so thx for that ^_^ |
|
|
Rob
USA
2615 Posts |
Posted - 07/18/2012 : 23:58:14
|
Oh right, because S+ would consume AHK's middle click and ctrl+t...duh!
Yeah, I'm going to add an action that will return the cursor type. Though you'll likely still have to use the acConsumePhysicalInput calls because mouse movement can interfere with synthesized positioning as the fellow making gestures for Notion discovered..and why I created that action. |
|
|
Rob
USA
2615 Posts |
Posted - 07/19/2012 : 10:20:29
|
Ok, added acGetMouseCursorType in 2.2.5 and the script below works for me in Firefox. I added the acDelay(20) after the first mouse move to ensure Firefox had time to actually change the cursor (sometimes it was too fast and didn't think it was a hand).
acConsumePhysicalInput(1)
acMouseMove(gsx,gsy)
acDelay(20)
if acGetMouseCursorType() == "HAND" then
acMouseClick(gsx, gsy, 1, 1, 1)
else
acSendKeys("^t")
end
acMouseMove(gex,gey)
acConsumePhysicalInput(0) |
|
|
Rob
USA
2615 Posts |
Posted - 07/19/2012 : 12:32:51
|
The script above also works with Chrome and Internet Explorer, for anyone reading this who wants this functionality. |
|
|
SomeGuy12
20 Posts |
Posted - 07/19/2012 : 13:28:48
|
Thanks, works like a charm! |
|
|
SomeGuy12
20 Posts |
Posted - 07/21/2012 : 04:39:44
|
Was thinking, is there any way for S+ to know if some text is being selected? As a condition added to the code above which then would do something else if text was selected. That would go great with the kingron code for searching for selected word or this AHK script http://www.autohotkey.com/community/viewtopic.php?f=2&t=85152 which does it even better. All in one gesture. |
Edited by - SomeGuy12 on 07/21/2012 04:46:59 |
|
|
Rob
USA
2615 Posts |
Posted - 07/21/2012 : 08:10:27
|
The only way I can think of would be to get the current clipboard text, then send ctrl+c and comparing the clipboard contents against the initial clipboard. If they don't match, assume that text was selected and perform a search. I haven't tried it, but seems like it should work. |
|
|
SomeGuy12
20 Posts |
Posted - 07/21/2012 : 19:23:37
|
Is that doable with S+ currently? And how would i implement that into the script above as a third condition? |
|
|
Rob
USA
2615 Posts |
Posted - 07/21/2012 : 19:50:15
|
This script technically works, but it's not really ideal since sending CTRL+C without anything selected (in Chrome, anyway) causes Chrome to play a "ding" sound to let you know there was nothing to copy.
However, it seems Firefox doesn't play a ding and it works..but this isn't very clean (nor is there a better way I'm able to think of at the moment). I suspect you'll run into oddities that will make sense, but could be annoying...not that I have an example, just a feeling. The delays are to give time for the clipboard operations to take place.
local sClipBefore = acGetClipboardText()
acSendKeys("{DELAY=50}^c")
acDelay(50)
local sClipAfter = acGetClipboardText()
acDelay(50)
if sClipBefore ~= sClipAfter then
local s = 'https://www.google.com/search?hl=en&output=search&q='..sClipAfter
acShellExecute("open","rundll32.exe",
"url.dll,FileProtocolHandler "..s, nil, 1)
else
acConsumePhysicalInput(1)
acMouseMove(gsx,gsy)
acDelay(20)
if acGetMouseCursorType() == "HAND" then
acMouseClick(gsx, gsy, 1, 1, 1)
else
acSendKeys("^t")
end
acMouseMove(gex,gey)
acConsumePhysicalInput(0)
end
|
|
|
SomeGuy12
20 Posts |
Posted - 07/21/2012 : 22:07:08
|
Thanks it worked nicely. |
|
|
xpectmore
14 Posts |
Posted - 05/29/2014 : 06:45:02
|
i was able to use new tab until i cut it from internet browser and i paste it on Global Actions...
then i put my script there :
local iHandle = acGetOwnerWindowByPoint(gsx, gsy)
acActivateWindow(iHandle,0,0)
acSendKeys("^t")
acMessageBox("new tab","new tab ",nil)
after this i draw a new stroke "Z" ,so now if i describe a "Z" in a active or inactive browser will open a new tab !!! and i get that window that confirm me i wasn't wrong.
NICE PROGRAM , i like this !!! |
|
|
Strokeman
33 Posts |
Posted - 06/13/2014 : 09:08:40
|
quote: Originally posted by Rob
This script technically works, but it's not really ideal since sending CTRL+C without anything selected (in Chrome, anyway) causes Chrome to play a "ding" sound to let you know there was nothing to copy.
However, it seems Firefox doesn't play a ding and it works..but this isn't very clean (nor is there a better way I'm able to think of at the moment). I suspect you'll run into oddities that will make sense, but could be annoying...not that I have an example, just a feeling. The delays are to give time for the clipboard operations to take place.
local sClipBefore = acGetClipboardText()
acSendKeys("{DELAY=50}^c")
acDelay(50)
local sClipAfter = acGetClipboardText()
acDelay(50)
if sClipBefore ~= sClipAfter then
local s = 'https://www.google.com/search?hl=en&output=search&q='..sClipAfter
acShellExecute("open","rundll32.exe",
"url.dll,FileProtocolHandler "..s, nil, 1)
else
acConsumePhysicalInput(1)
acMouseMove(gsx,gsy)
acDelay(20)
if acGetMouseCursorType() == "HAND" then
acMouseClick(gsx, gsy, 1, 1, 1)
else
acSendKeys("^t")
end
acMouseMove(gex,gey)
acConsumePhysicalInput(0)
end
Thanks rob for this. Coming from FireGestures background (Firefox addon) , using it for years, i have those gestures bound to my DNA now and this was one of it. Finally searched this thread and it worked. only issue being its kinda slow Can we remove or drastically reduce the "delay" in this code?what can be the problems i tried editing all delays to 5 ms times & its far better |
Edited by - Strokeman on 06/13/2014 09:09:58 |
|
|
Rob
USA
2615 Posts |
Posted - 06/16/2014 : 10:56:35
|
Yes, there's no reason to have such long delays...a lot of times I leave it in there in my posts for people with slower computers. |
|
|
Strokeman
33 Posts |
Posted - 06/29/2014 : 06:20:30
|
thanks rob. One more question on this topic itself:
Regarding this code if acGetMouseCursorType() == "HAND" then acMouseClick(gsx, gsy, 1, 1, 1) else acSendKeys("^t")
what i understand is, It says if cursor hand shaped, click the link else send new tab shortcut of CTRL+T. am i right? what if instead of clicking(which opens link in new tab), i need to add a gesture for open the link in new window ?
I come from FireGestures background, & had set a down swipe for opening link in new tab & upward swipe in new window, so asking :) |
Edited by - Strokeman on 06/29/2014 06:22:18 |
|
|
Daniel
13 Posts |
Posted - 12/14/2017 : 16:26:31
|
I decided to resurrect this thread rather than create a new one because my question had to do with a gesture that existed in FireGestures. Pretty much the only remaining reason I haven't upgraded to the newest version of firefox is because FireGestures is now broken with FF Quantum. I'm really happy I came across S+, incredible work. Anyway...
One of the most useful gestures I used in Firefox was a gesture where you hold a modifier button, in my case Ctrl, and then draw a line through every link you wanted open in a new tab. So if I were on a webpage like google and I wanted to open up the first five search results, I just hold Ctrl and draw a gesture through the first five search result links. I also used this on my speed dial page where I drew a line through every page I wanted opened at that moment.
I am not super experienced with scripting so I can't really follow the stuff being said in here. It would require Windows know it is passing over links and you said in an earlier post "there's no way via the Windows API to detect what's below the mouse". Would it be possible as a work around to just have it Middle click every point along the gesture path? I imagine not since actions being performed are probably completely dependent on what shapes are being drawn. Well, I appreciate any help.
Also, I don't know if it matters, but I'm not positive whether I will even be going back to firefox. If there was some kind of solution that worked in Chrome but not Firefox. I would be happy with that. |
|
|
Rob
USA
2615 Posts |
Posted - 12/14/2017 : 17:01:24
|
Daniel,
If you restrict your gesture to a (relatively) straight line, you could accomplish this by leveraging the variables passed into each action.
For example, if you made it a straight line from top down, you could certainly do something like:
acConsumePhysicalInput(1) --To ensure your own mouse movements don't interfere
local i = gsy --Set to the starting Y coordinate of the gesture
while i < gey do --gey is the ending Y coordinate
--might need to call acMouseMove before the click, but I don't think so
acMouseClick(gsx, i, 1, 1, 1) --click the middle button along the same X (left) axis, but with changing vertical (Y) position
acDelay(10) --add a little delay between clicks, may be able to go less
i = i + 10 --instead of middle clicking at every pixel, only every 10..change to whatever works
end
acConsumePhysicalInput(0) --re-enable mouse/keyboard input I haven't tested the above, just typing it out based on what I think could work. Be careful as the above script would likely result in an infinite loop if you used it to draw an upward gesture (bottom to top) (since it's adding to i, but testing that i is less than gey, which would never be satisfied in the opposite direction)...that or eventually it would hit a variable boundary and maybe crash...or maybe just lock your system/S+ up pretty hard.
Also make sure to only add the calls to acConsumePhysicalInput once you've been able to test that the script works, otherwise if you disable input and the script bombs before it's able to call acConsumePhysicalInput(0), you'll pretty much have to hard power off your computer.
You are correct that short of testing for the HAND cursor (which is unreliable unless you use a stock cursor set), there's no reliable way to know what's under the cursor based on the data inside the application (web browser area inside Firefox).
You could modify the above to go along the path and check the cursor type, but you'd definitely have to call acMouseMove, then delay (for Windows to react to the cursor change, then check if HAND and click.
In the new version of S+ that I'm working on (yes people, I actually am working on it again!), the full array of points made during the gesture are passed into the script, which would make this a little more flexible. But it would still be pretty much a hack like the above.
However, if you want to get creative in the script, you could certainly make it more flexible by determining the direction based on coordinates contained in gsx, gsy, gex, gey, but it seems like that would be overkill.
|
|
|
Daniel
13 Posts |
Posted - 12/14/2017 : 17:26:12
|
Wow, thanks for getting back so quickly. That's incredible. I'll probably just take what you wrote out there and see how it works for me. I don't have the know-how to modify any other variables like the HAND cursor check or the gsx, gsy, gex, gey coordinate stuff. Maybe I'll just have to live without it because the risks you laid out make me nervous. haha.
I had seen the post saying that you had a newer version of S+ coming out eventually. Really looking forward to it. |
|
|
Hard.Wired
84 Posts |
Posted - 12/14/2017 : 18:16:56
|
You know. The more I read these forums, the more I think I am never going to finish tweaking my own config. This is great stuff!
I'll work in this tonight, but Rob will probably beat me to it! |
|
|
Hard.Wired
84 Posts |
Posted - 12/14/2017 : 19:20:16
|
Ok, got it to work (Note: I have the gesture going from the bottom up):
acActivateWindow(nil, gsx, gsy, 0)
acConsumePhysicalInput(1)
local t = 0
local i = gsy
while i > gey do
acMouseMove(gsx, i)
acDelay(5)
if acGetMouseCursorType() == "HAND" then
if t == 0 then
acMouseClick(gsx, i, 1, 1, 1)
t = 1
end
else
t = 0
end
i = i - 1
end
acConsumePhysicalInput(0)
I'll come back and comment it better... gotta run. |
|
|
Daniel
13 Posts |
Posted - 12/14/2017 : 21:29:45
|
You guys are such geniuses. Wish I knew how to jump in.
I added both actions to S+ and thought I would share my results. The original one by Rob worked as intended but there was an unexpected consequence that I didn't even think about. It middle clicks everything along the way regardless of whether or not it has been clicked before. So it end up middle clicking the same link a bunch of times resulting in a bunch of redundant tabs.
Hard.Wired's script seemed to correct this opening each link only one time.
Nice work, both of you. One other issue that seemed to be happening and maybe it is my fault somehow and I am messing something up. When I use a modifier like Ctrl or Shift, it's input wouldn't stop. So even after everything is done. It still thinks I am pushing the button down. So actually, when using the Shift key as a modifier it would interfere with the script because since it still thinks I am holding that shift key down, Shift+Middle Click is openlink in new foreground tab.
|
|
|
Rob
USA
2615 Posts |
Posted - 12/14/2017 : 21:55:47
|
You could try calling acSendShiftUp() at the top of the script.
Yeah, I noticed he had the t variable, which makes sense to only click once per hand cursor. |
|
|
Cerberus
Netherlands
86 Posts |
Posted - 12/21/2017 : 19:22:16
|
- Isn't there a new Firefox extension that can do the same things as Firegestures? At work, I switched to a different extension, whose name eludes me now, which could do most of the things I remembered Firegestures could—although I'm not sure whether it can do this, too.
- There used to be a special extension that allowed the opening of all links inside a rectangle. Perhaps such a specialised extension now also exists in the new extension format?
- The same applies to a Greasemonkey script (Greaemonkey itself has been ported to the new Firefox format). |
Edited by - Cerberus on 12/21/2017 19:28:21 |
|
|
Hard.Wired
84 Posts |
Posted - 02/27/2018 : 09:33:58
|
Slight update to the version I am using for reliability / cross browser usage:
acActivateWindow(nil, gsx, gsy, 0)
acConsumePhysicalInput(1)
local t = 0
local i = gsy
while i < gey do
acMouseMove(gsx, i)
acDelay(1)
if acGetMouseCursorType() == "HAND" then
if t == 0 then
acMouseClick(gsx, i, 1, 1, 0)
acMouseClick(gsx, i, 1, 0, 1)
t = 1
end
else
t = 0
end
i = i + 2
end
acConsumePhysicalInput(0)
Changes: * Stroke direction is now downward. * acMouseClick up and down click commands were separated to provide better timing to avoid accidental double clicking. * i variable index increments by +2 to avoid "hesitation" glitch on some systems.
|
|
|
vinzbe
1 Posts |
Posted - 04/18/2018 : 21:52:05
|
I made some changes on the code from previous post:
• additional reliability. • open a new tab when there is no link • open links either in the background or foreground (see variable 'open_link_in_background')
It should work on all browsers.
Edit: improved reliability : acDelay(1) -> acDelay(10) Edit2: improved again reliability
local open_link_in_background = false
acActivateWindow(nil, gsx, gsy, 0)
acConsumePhysicalInput(1)
local clicked = false
local i = gsy
local i_end = i + 6
while i < i_end do
acMouseMove(gsx,i)
acDelay(20)
if acGetMouseCursorType() == "HAND" then
if not clicked then
if open_link_in_background then
acMouseClick(gsx, i, 1, 1, 1)
else
acSendControlDown()
acSendShiftDown()
acMouseClick(gsx, i, 2, 1, 1)
acSendShiftUp()
acSendControlUp()
end
clicked = true
end
end
i = i + 2
end
if not clicked then
acSendKeys("^t")
end
acMouseMove(gex,gey)
acConsumePhysicalInput(0)
|
Edited by - vinzbe on 04/26/2018 14:43:19 |
|
|
|
Topic |
|
|
|