Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Restrict mouse move to area.


  • Please log in to reply
7 replies to this topic
Locaj
  • Guests
  • Last active:
  • Joined: --
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

purloinedheart
  • Members
  • 538 posts
  • Last active: May 21 2013 04:13 AM
  • Joined: 04 Apr 2008
MouseGetPos
MouseMove
Loop

Easy to make

randallf
  • Members
  • 711 posts
  • Last active: Jan 07 2014 11:45 PM
  • Joined: 06 Jul 2009
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

Leef_me
  • Moderators
  • 8394 posts
  • Last active: Today, 07:42 AM
  • Joined: 08 Apr 2009
***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



x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
<!-- m -->http://www.autohotke... ... 537#409537<!-- m -->

x79animal
  • Members
  • 1021 posts
  • Last active: May 14 2013 04:21 PM
  • Joined: 01 May 2010
bump because this is useful, i think this should be built into ahk :p

dsunde
  • Members
  • 4 posts
  • Last active: Feb 22 2008 07:27 AM
  • Joined: 24 Aug 2007
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?

nimda
  • Members
  • 4368 posts
  • Last active: Jan 15 2014 02:47 PM
  • Joined: 26 Dec 2010
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