Page 1 of 1

want to forbid cursor from moving to the right of x1800

Posted: 27 Sep 2020, 00:53
by tatagi
I want to forbid mouse cursor from moving to the right of x1800 when notepad is active

is this possible?

so the goal is , to limit the mouse movement x from 0 to 1800, and all y

Re: want to forbid cursor from moving to the right of x1800

Posted: 27 Sep 2020, 08:30
by mikeyww
Although there is probably a mouse hook somewhere for this, you could also run a timer that checks the mouse position and then moves the mouse. Example.

Re: want to forbid cursor from moving to the right of x1800

Posted: 28 Sep 2020, 01:03
by iseahound
Yep. There exists a clipcursor function.

https://www.autohotkey.com/boards/viewtopic.php?p=287979#p287979

Code: Select all

Esc::	ExitApp
f1::     ;on
	ClipCursor( True, 100, 100, 200, 200)
Return

f2::	;off
	ClipCursor( False)
return

ClipCursor( Confine:=True, x1:=0 , y1:=0, x2:=1, y2:=1 ) {

	pData := DllCall("GlobalAlloc", "uint", 0x0, "uptr", 16, "ptr")
	NumPut(x1, pData+0, "int")
	NumPut(y1, pData+4, "int")
	NumPut(x2, pData+8, "int")
	NumPut(y2, pData+12, "int")
	
	value :=  Confine ? DllCall( "ClipCursor", "ptr", pData ) : DllCall( "ClipCursor" )
	DllCall("GlobalFree", "ptr",pData)

	return value
}