want to forbid cursor from moving to the right of x1800

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
tatagi
Posts: 181
Joined: 23 Aug 2018, 11:17

want to forbid cursor from moving to the right of x1800

Post by tatagi » 27 Sep 2020, 00:53

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

User avatar
mikeyww
Posts: 27115
Joined: 09 Sep 2014, 18:38

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

Post by mikeyww » 27 Sep 2020, 08:30

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.

iseahound
Posts: 1451
Joined: 13 Aug 2016, 21:04
Contact:

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

Post by iseahound » 28 Sep 2020, 01:03

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
}

Post Reply

Return to “Ask for Help (v1)”