I just use the aforementioned SKAN's code, and modified the clip region, works nice for me.
Code:
Confine := 1
ClipCursor( Confine, 0, 0, A_ScreenWidth, A_ScreenHeight )
^F2:: ; Hotkey will toggle status
Confine := !Confine
ClipCursor( Confine, 0, 0, A_ScreenWidth, A_ScreenHeight )
Return
ClipCursor( Confine=True, x1=0 , y1=0, x2=1, y2=1 ) {
VarSetCapacity(R,16,0), NumPut(x1,&R+0),NumPut(y1,&R+4),NumPut(x2,&R+8),NumPut(y2,&R+12)
Return Confine ? DllCall( "ClipCursor", UInt,&R ) : DllCall( "ClipCursor" )
}
[/code]