This App is No Longer Maintained. Visit the Replacement at StrokesPlus.net

StrokesPlus Forum
                       
StrokesPlus Forum
Home | Profile | Active Topics
Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 About
 Did you know...
 DYK: Running different scripts by a single gesture
 Forum Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

breakcore

Russia
74 Posts

Posted - 10/31/2012 :  19:08:15  Show Profile

Am I allowed to start a topic in this section?=)

This trick might be handy for someone who has too many different gestures.
If you assign the following script to the simple "right" gesture you'll be able to run a certain part of a script according to specified gesture length:


script:
short_len=200  	--better be specified in global script
if gex-gsx<short_len then 
   acMessageBox("do something1",'message',nil)
else 
   acMessageBox("do something2",'message',nil)
end
--for the left gesture you need to change the "gex-gsx" to "gsx-gex", for the "up" gesture to "gsy-gey", for the down to "gey-gsy"

Now you can run two actions by one gesture.
But you can also run actions according to the mouse position at which the gesture had started. This is only suitable for the actions which doesn't require a certain mouse position (like when selecting files or something)
If you visually divide your display 3 times horizontally and 3 times vertically it will be a grid with 9 sectors. The following script runs a certain subscript according to what sector of the screen the gesture had started on:


global script:
x_res=acGetMonitorRight(acGetMonitorFromPoint(gsx, gsy), 0)   --display width
y_res=acGetMonitorBottom(acGetMonitorFromPoint(gsx, gsy), 0) --display height

script: {any gesture}
sector=math.ceil(gsx/(x_res/3))+(3*(math.floor (gsy/(y_res/3))))  -- calculates the sector on which the gesture had started
--123
--456
--789
if sector==1 then acMessageBox("do something",'message',nil)
elseif sector==2 then acMessageBox("do something1",'message',nil)
elseif sector==3 then acMessageBox("do something2",'message',nil)
elseif sector==4 then acMessageBox("do something3",'message',nil)
elseif sector==5 then acMessageBox("do something4",'message',nil)						
elseif sector==6 then acMessageBox("do something5",'message',nil)
elseif sector==7 then acMessageBox("do something6",'message',nil)
elseif sector==8 then acMessageBox("do something7",'message',nil)
elseif sector==9 then acMessageBox("do something8",'message',nil)
end
--for 2x2 grid (4 sectors) use: sector=math.ceil(gsx/(x_res/2))+(2*(math.floor (gsy/(y_res/2))))
--4x3 grid (12 sectors): sector=math.ceil(gsx/(x_res/4))+(4*(math.floor (gsy/(y_res/3))))

Now you can run nine actions by a single gesture. If that's not enough you can also utilize the gesture length:

script:
sector=math.ceil(gsx/(x_res/3))+(3*(math.floor (gsy/(y_res/3))))
if gsx-gex<short_len then
	if sector==1 then acMessageBox("do something1",'message',nil)
	elseif sector==2 then acMessageBox("do something2",'message',nil)
	elseif sector==3 then acMessageBox("do something3",'message',nil)
	elseif sector==4 then acMessageBox("do something4",'message',nil)
	elseif sector==5 then acMessageBox("do something5",'message',nil)						
	elseif sector==6 then acMessageBox("do something6",'message',nil)
	elseif sector==7 then acMessageBox("do something7",'message',nil)
	elseif sector==8 then acMessageBox("do something8",'message',nil)
	elseif sector==9 then acMessageBox("do something9",'message',nil)
	end
else
	if sector==1 then acMessageBox("do something10",'message',nil)
	elseif sector==2 then acMessageBox("do something11",'message',nil)
	elseif sector==3 then acMessageBox("do something12",'message',nil)
	elseif sector==4 then acMessageBox("do something13",'message',nil)
	elseif sector==5 then acMessageBox("do something14",'message',nil)						
	elseif sector==6 then acMessageBox("do something15",'message',nil)
	elseif sector==7 then acMessageBox("do something16",'message',nil)
	elseif sector==8 then acMessageBox("do something17",'message',nil)
	elseif sector==9 then acMessageBox("do something18",'message',nil)
	end
end


18 actions!
That is it. Sorry for my English, if I have mistakes.

Edited by - breakcore on 10/31/2012 19:12:50

Rob

USA
2615 Posts

Posted - 10/31/2012 :  20:57:05  Show Profile  Visit Rob's Homepage
Post away!
Go to Top of Page

wikii2008

4 Posts

Posted - 12/26/2012 :  21:19:36  Show Profile
Great! I can define more function for simple strokes.
Go to Top of Page

Rob

USA
2615 Posts

Posted - 12/27/2012 :  10:11:46  Show Profile  Visit Rob's Homepage
Just a quick note; the following lines may not work when on a non-primary screen (with multiple monitors):
x_res=acGetMonitorRight(acGetMonitorFromPoint(gsx, gsy), 0)   --display width
y_res=acGetMonitorBottom(acGetMonitorFromPoint(gsx, gsy), 0) --display height

For example, on my system I have another monitor to the left of the primary monitor and its Right coordinate is 0 (left is -1680) since the primary starts at 0 and goes to 1920.

This code should work for single and multiple monitor setups:
local hMonitor = acGetMonitorFromPoint(gsx, gsy)
x_res=acGetMonitorRight(hMonitor, 0) - acGetMonitorLeft(hMonitor, 0) --display width
y_res=acGetMonitorBottom(hMonitor, 0) - acGetMonitorTop(hMonitor, 0) --display height

I assigned hMonitor for performance reasons; acGetMonitor(...) enumerates all displays and is a heavy hitter from a code perspective, so it's best to minimize the calls to it when possible.
Go to Top of Page

breakcore

Russia
74 Posts

Posted - 12/27/2012 :  14:57:58  Show Profile
Thanks for correction Rob.
I've also made a function for this. My early script uses the whole display area, but sometimes it's good to have the grid with sectors within a window. Here is a function

global script:
local hMonitor = acGetMonitorFromPoint(gsx, gsy)
x_res=acGetMonitorRight(hMonitor, 0) - acGetMonitorLeft(hMonitor, 0) --display width
y_res=acGetMonitorBottom(hMonitor, 0) - acGetMonitorTop(hMonitor, 0) --display height

grid=function(h_sectors,v_sectors,gsx,gsy,control)
	if control==0 then
		sector=math.ceil(gsx/(x_res/h_sectors))+(h_sectors*(math.floor(gsy/(y_res/v_sectors))))
	else
		handle=acGetWindowByPoint(gsx, gsy)
		if control==1 then
			wr=acGetWindowRight(nil,gsx,gsy)
			wl=acGetWindowLeft(nil,gsx,gsy)
			wt=acGetWindowTop(nil,gsx,gsy)
			wb=acGetWindowBottom(nil,gsx,gsy)
		elseif control==2 then
			wr=acGetWindowRight(handle,nil,nil)
			wl=acGetWindowLeft(handle,nil,nil)
			wt=acGetWindowTop(handle,nil,nil)
			wb=acGetWindowBottom(handle,nil,nil)
		end
		ww=wr-wl --window width
		wh=wb-wt --window height
		sector=math.ceil((gsx-wl)/(ww/h_sectors))+(h_sectors*(math.floor ((gsy-wt)/(wh/v_sectors))))
		return handle --for further usage when needed
	end
end
control parameter is:
"0" - static grid on the whole display
"1" - grid for the whole window of an app
"2" - grid for the child window (only for apps with control qualifier specified, otherwise all child windows of an app window will allocate the same grid on them, which is a mess).


So for the whole display grid action script will look like:
grid(3,3,gsx,gsy,0) --3x3 grid 
if sector==1 then acMessageBox("do something1",'message',nil)
elseif sector==2 then acMessageBox("do something2",'message',nil)
elseif sector==3 then acMessageBox("do something3",'message',nil)
-----------and so on
end

Here is example for foobar2000 window:

action script:
grid(3,3,gsx,gsy,1)
if sector==1 then acMessageBox("do something1",'message',nil)
elseif sector==2 then acMessageBox("do something2",'message',nil)
elseif sector==3 then acMessageBox("do something3",'message',nil)
-----------and so on
end



2)for foobar2000 child window (playlist):

action script:
grid(1,5,gsx,gsy,2)
if sector==1 then acMessageBox("do something1",'message',nil)
elseif sector==2 then acMessageBox("do something2",'message',nil)
elseif sector==3 then acMessageBox("do something3",'message',nil)
-----------and so on
end



That is it.

Edited by - breakcore on 12/27/2012 15:13:37
Go to Top of Page

chandisciple

75 Posts

Posted - 03/21/2016 :  01:33:14  Show Profile
Amazing ! Breakcore - your script just made me shit bricks ! Very potential script. You rock man !

@ ROB ; I guess i still would go about using this script if i have to achieve this right ? i mean this was written in 2012 .hope you didn't upgrade your magic software with any alternate.
Go to Top of Page

Rob

USA
2615 Posts

Posted - 03/21/2016 :  07:05:04  Show Profile  Visit Rob's Homepage
Nothing has been built into S+ for this, so yes, go ahead and use this :)
Go to Top of Page

control_freak

51 Posts

Posted - 04/09/2016 :  18:36:36  Show Profile
i have tried this scrpit and it shows a small window with 1 written on when i try the short gesture
short_len=200 --better be specified in global script
if gex-gsx<short_len then
acMessageBox(acSendKeys("{BROWSERFORWARD}"))
else
acMessageBox(acSendKeys("{DELAY=50}@{RIGHT}"))
end
Go to Top of Page

control_freak

51 Posts

Posted - 04/09/2016 :  18:42:12  Show Profile
nvm figured out. acmessagebox was the problem.deleted it works fine now
Go to Top of Page

control_freak

51 Posts

Posted - 04/09/2016 :  19:49:01  Show Profile
if i want to include the two gestures to a upward left/right motion what should i change the gex-gsx to?
Go to Top of Page

breakcore

Russia
74 Posts

Posted - 10/31/2016 :  08:28:00  Show Profile
@control_freak
Thanks!
Yes, you just have to change the equation gsx-gex to gex-gex/gsy-gey/gey-gsy or anything else, depending on gesture type and your needs
Go to Top of Page

nober

29 Posts

Posted - 11/26/2018 :  07:46:12  Show Profile
There is a bug in the code.
sector=math.ceil(gsx/(x_res/3))+(3*(math.floor (gsy/(y_res/3))))


If one were to draw at the left edge of the screen, gsx would be 0, therefore, the sector would be one less than expected. For example, using a 3 x 3 grid, drawing at the left edge of sectors 1, 4, 7, shown in the picture, the code's sector would return 0, 3, or 6, respectively.

There are two solutions, either add a line above
if gsx == 0 then gsx = 1 end
, or modify the equation, because the default mouse cursor takes up one pixel, a positive number > 0, and #8804; 1 would work without causing a bump in sector
sector=math.ceil(gsx + 1/(x_res/3))+(3*(math.floor (gsy/(y_res/3))))
. The latter is faster.

Edited by - nober on 01/24/2020 10:22:09
Go to Top of Page
  Previous Topic Topic Next Topic  
 Forum Locked
 Printer Friendly
Jump To:
StrokesPlus Forum © 2011-2018 Rob Yapchanyk Go To Top Of Page
Snitz Forums 2000