How can I force GetMouseGesture() to fire instantly? Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
daniel
Posts: 17
Joined: 23 May 2016, 22:41

How can I force GetMouseGesture() to fire instantly?

Post by daniel » 06 May 2021, 15:22

I’ve been using GetMouseGesture() to execute mouse gestures. It’s great, but I’d like for functions to fire instantly without having to release the key. I don’t know where to begin. Help is much appreciated.

The original thread is at https://www.autohotkey.com/boards/viewtopic.php?t=57037

And this is the code:

Code: Select all

~Ctrl::		;gesture hotkey, i imagine most would use a mousekey for gestures,ctrl is simply an example suitable for testing as i've got radial menu running...
	GetMouseGesture(True)
	While GetKeyState(LTrim(A_ThisHotkey,"~")){
		ToolTip % MG := GetMouseGesture()
		Sleep 150
	}
	;left <= 20% of screen width, right >= 80% of screen width, top <= 20% of screen height, bottom >= 80% of screen height
	MQ := SubStr(MouseQuadrant(20,80,20,80),1,1)	;take only the first letter of the quadrant,for simplified function names...
	IsFunc(MG "_" MQ) ? %MG%_%MQ%() : (IsFunc(MG) ? %MG%() : "")	;example allows creation of gestures by defining functions that comprise U,D,R,L as function name,with no upper limit on the extent of the gesture,i.e UDUDUDUDL for ex.
	ToolTip
	GetMouseGesture(True)
Return


UDL(){
	MsgBox % "Function Run,if no function was defined for specific quadrant. Or Quadrant Has No Assigned Function.`n`n CurrentQuadrant:`n`t" MouseQuadrant(20,80,20,80)
}

UDL_T(){	;function defined gesture example for example below
	MsgBox Gesture On Top
}

UDL_L(){	;function defined gesture example for example below
	MsgBox Gesture To The LEFT
}

UDL_R(){	;function defined gesture example for example below
	MsgBox Gesture To The Right
}


;returns if screen is on top,bottom,center,left,right area of screen given the defined scope in percent of each area...see example.
/*
					Top
	___________________________________
	L	|						|	R
	E	|						|	y
	F	|		C E N T E R		|	T
	T	|						|
	____|_______________________|______
					Bottom
*/
;defined scopes are in 'percent',i.e left scope means anything below defined % is designated left,right scope is anything above defined %...
MouseQuadrant(leftScope,rightScope,topScope,bottomScope,coordMode:="screen"){	;coordMode should either be 'window' or 'screen'
	CoordMode, Mouse, % coordMode
	MouseGetPos, mX, mY, mHwnd, mCtrl
	WinGetPos, wX, wY, wW, hH, A
	
	If (mX <= leftScope/100*(coordMode = "screen" ? A_ScreenWidth : wW) && mY >= topScope/100*(coordMode = "screen" ? A_ScreenHeight : hH) && mY <= bottomScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "LEFT"
	Else If (mX >= rightScope/100*(coordMode = "screen" ? A_ScreenWidth : wW) && mY >= topScope/100*(coordMode = "screen" ? A_ScreenHeight : hH) && mY <= bottomScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "RIGHT"
	Else If (mY <= topScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "TOP"
	Else If (mY >= bottomScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "BOTTOM"
	Else
		Return "CENTER"
	
}


GetMouseGesture(reset := false){
	Static
	mousegetpos,xpos2, ypos2
	dx:=xpos2-xpos1,dy:=ypos1-ypos2
	,( abs(dy) >= abs(dx) ? (dy > 0 ? (track:="u") : (track:="d")) : (dx > 0 ? (track:="r") : (track:="l")) )	;track is up or down, left or right
	,abs(dy)<4 and abs(dx)<4 ? (track := "") : ""	;not tracking at all if no significant change in x or y
	,xpos1:=xpos2,ypos1:=ypos2
	,track<>SubStr(gesture, 0, 1) ? (gesture := gesture . track) : ""	;ignore track if not changing since previous track
	,gesture := reset ? "" : gesture
	Return gesture
}
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: How can I force GetMouseGesture() to fire instantly?

Post by boiler » 06 May 2021, 15:48

When would you want it to fire? Are you limiting it to just one directional gesture? It's designed to allow multiple directions to be strung together, and the way it knows when to stop stringing them together is when you let go of the gesture hotkey.
daniel
Posts: 17
Joined: 23 May 2016, 22:41

Re: How can I force GetMouseGesture() to fire instantly?

Post by daniel » 07 May 2021, 03:45

Correct. I want to limit it to one directional gesture.
User avatar
boiler
Posts: 16767
Joined: 21 Dec 2014, 02:44

Re: How can I force GetMouseGesture() to fire instantly?  Topic is solved

Post by boiler » 07 May 2021, 09:26

OK. This does that and it has the functions set up for all four gestures for all 5 areas (4 quadrants and middle).

Code: Select all

~Ctrl::		;gesture hotkey, i imagine most would use a mousekey for gestures,ctrl is simply an example suitable for testing as i've got radial menu running...
	GetMouseGesture(True)
	loop
		Sleep 150
	until MG := GetMouseGesture()
	;left <= 20% of screen width, right >= 80% of screen width, top <= 20% of screen height, bottom >= 80% of screen height
	MQ := SubStr(MouseQuadrant(20,80,20,80),1,1)	;take only the first letter of the quadrant,for simplified function names...
	IsFunc(MG "_" MQ) ? %MG%_%MQ%() : (IsFunc(MG) ? %MG%() : "")	;example allows creation of gestures by defining functions that comprise U,D,R,L as function name,with no upper limit on the extent of the gesture,i.e UDUDUDUDL for ex.
	ToolTip
	GetMouseGesture(True)
Return


U(){
	MsgBox Up gesture in no specific quadrant
}

U_T(){	;function defined gesture example for example below
	MsgBox Up gesture in top area
}

U_L(){	;function defined gesture example for example below
	MsgBox Up gesture in left area
}

U_R(){	;function defined gesture example for example below
	MsgBox Up gesture in right area
}

U_B(){	;function defined gesture example for example below
	MsgBox Up gesture in bottom area
}

L(){
	MsgBox Left gesture in no specific quadrant
}

L_T(){	;function defined gesture example for example below
	MsgBox Left gesture in top area
}

L_L(){	;function defined gesture example for example below
	MsgBox Left gesture in left area
}

L_R(){	;function defined gesture example for example below
	MsgBox Left gesture in right area
}

L_B(){	;function defined gesture example for example below
	MsgBox Left gesture in bottom area
}

R(){
	MsgBox Right gesture in no specific quadrant
}

R_T(){	;function defined gesture example for example below
	MsgBox Right gesture in top area
}

R_L(){	;function defined gesture example for example below
	MsgBox Right gesture in left area
}

R_R(){	;function defined gesture example for example below
	MsgBox Right gesture in right area
}

R_B(){	;function defined gesture example for example below
	MsgBox Right gesture in bottom area
}

D(){
	MsgBox Down gesture in no specific quadrant
}

D_T(){	;function defined gesture example for example below
	MsgBox Down gesture in top area
}

D_L(){	;function defined gesture example for example below
	MsgBox Down gesture in left area
}

D_R(){	;function defined gesture example for example below
	MsgBox Down gesture in right area
}

D_B(){	;function defined gesture example for example below
	MsgBox Down gesture in bottom area
}

;returns if screen is on top,bottom,center,left,right area of screen given the defined scope in percent of each area...see example.
/*
					Top
	___________________________________
	L	|						|	R
	E	|						|	y
	F	|		C E N T E R		|	T
	T	|						|
	____|_______________________|______
					Bottom
*/
;defined scopes are in 'percent',i.e left scope means anything below defined % is designated left,right scope is anything above defined %...
MouseQuadrant(leftScope,rightScope,topScope,bottomScope,coordMode:="screen"){	;coordMode should either be 'window' or 'screen'
	CoordMode, Mouse, % coordMode
	MouseGetPos, mX, mY, mHwnd, mCtrl
	WinGetPos, wX, wY, wW, hH, A
	
	If (mX <= leftScope/100*(coordMode = "screen" ? A_ScreenWidth : wW) && mY >= topScope/100*(coordMode = "screen" ? A_ScreenHeight : hH) && mY <= bottomScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "LEFT"
	Else If (mX >= rightScope/100*(coordMode = "screen" ? A_ScreenWidth : wW) && mY >= topScope/100*(coordMode = "screen" ? A_ScreenHeight : hH) && mY <= bottomScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "RIGHT"
	Else If (mY <= topScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "TOP"
	Else If (mY >= bottomScope/100*(coordMode = "screen" ? A_ScreenHeight : hH))
		Return "BOTTOM"
	Else
		Return "CENTER"
	
}


GetMouseGesture(reset := false){
	Static
	mousegetpos,xpos2, ypos2
	dx:=xpos2-xpos1,dy:=ypos1-ypos2
	,( abs(dy) >= abs(dx) ? (dy > 0 ? (track:="u") : (track:="d")) : (dx > 0 ? (track:="r") : (track:="l")) )	;track is up or down, left or right
	,abs(dy)<4 and abs(dx)<4 ? (track := "") : ""	;not tracking at all if no significant change in x or y
	,xpos1:=xpos2,ypos1:=ypos2
	,track<>SubStr(gesture, 0, 1) ? (gesture := gesture . track) : ""	;ignore track if not changing since previous track
	,gesture := reset ? "" : gesture
	Return gesture
}
daniel
Posts: 17
Joined: 23 May 2016, 22:41

Re: How can I force GetMouseGesture() to fire instantly?

Post by daniel » 07 May 2021, 09:40

Thank you, boiler.

Thank you very much!!!
Post Reply

Return to “Ask for Help (v1)”