Jump to content


Restrict mouse move to area.


  • Please log in to reply
7 replies to this topic

#1 Locaj

Locaj
  • Guests

Posted 02 September 2009 - 03:26 PM

Hi.

Tried to do script that will restrict certain area of screen in my game but no luck.

Is it possible to force mouse to stay on mid screen and not be able to go to top of screen? I would like to restrict area 0-50 on top of screen. Im playing in 800*600 and i dont want mouse to go to top 50 pixels at all.

That would have to work all the time. Even if i hold shift or ctrl or alt. Or even if i hold Lmouse button or Rmouse button.

Is it possible at all?

Thanks

#2 purloinedheart

purloinedheart
  • Members
  • 538 posts

Posted 02 September 2009 - 03:27 PM

MouseGetPos
MouseMove
Loop

Easy to make

#3 randallf

randallf
  • Members
  • 708 posts

Posted 02 September 2009 - 03:36 PM

You may want to adjust the 'if MouseY' line number to prevent it from moving higher. This may not work if there is NO tolerance at ALL in the game, i.e. if your mouse is there it triggers, but it might help.

#IfWinActive My Game Window Title 

SetTimer, MouseCheck, 100 ;check every 100ms or however often


MouseCheck:
MouseGetPos, MouseX, MouseY


If MouseY < 50
{
	MouseMove, %MouseX%, 51
}

Return

Pause::
ExitApp

edit, removed msgbox

#4 Leef_me

Leef_me
  • Moderators
  • 7704 posts

Posted 02 September 2009 - 07:29 PM

***AHK invisible fence***

No timers required! Does not coddle you mouse! :wink:

; the '*' is Wildcard: Fire the hotkey even if extra modifiers are being held down. 
*ScrollLock:: ; Hotkey will toggle status, scroll-lock key
Confine := !Confine

ClipCursor( Confine, 0, 50, 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" )
}

; for reference, I got the script from here

;Is there a way to use AHK to effectively ignore the y-axis while still retaining full x-axis ;functionality? 
;
;http://www.autohotkey.com/forum/topic42365.html&highlight=draw+mouse



#5 x79animal

x79animal
  • Members
  • 1021 posts

Posted 25 December 2010 - 04:56 PM

<!-- m -->http://www.autohotke... ... 537#409537<!-- m -->

#6 x79animal

x79animal
  • Members
  • 1021 posts

Posted 18 April 2011 - 03:34 PM

bump because this is useful, i think this should be built into ahk :p

#7 dsunde

dsunde
  • Members
  • 4 posts

Posted 23 June 2011 - 04:26 PM

Sorry to bump an old post. I found that this script works great except for one major problem. If you ever drag the mouse (left OR right button), the mouse restriction gets turned off. The script does not know that, so it thinks the restriction is still in effect. So if you press Scroll Lock to toggle it, the script toggles it OFF. You have to press Scroll Lock a second time to toggle the restriction back on.

I guess the Windows programmers decided that if you are dragging the mouse, all restrictions need to go away.

Obviously this is a major problem for this script. The only thing I can think to do is add to it to detect a left or right drag, pass the drag on through, but also re-enable the mouse restriction. Is this possible? Any ideas on how to do it?

#8 nimda

nimda
  • Members
  • 4301 posts

Posted 23 June 2011 - 06:12 PM

It turns out that the cursor is unclipped ever time a new window is created.
I think you will need a timer, and/or a ShellHook and/or make your own clipcursor with loop