Lock cursor to specific window

Ask gaming related questions (AHK v1.1 and older)
Friendlyrock
Posts: 2
Joined: 16 May 2018, 06:27

Lock cursor to specific window

16 May 2018, 06:34

Need help locking my cursor to the game I'm playing (BloodRayne). If I move the cursor to the left or right it will go off of the game and messes everything up.
Qysh
Posts: 143
Joined: 24 Apr 2018, 09:16

Re: Lock cursor to specific window

16 May 2018, 12:30

Hope this works ;)

F6 to toggle

Code: Select all

#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#MaxThreadsPerHotkey 255
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, 0, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetWorkingDir %A_ScriptDir%
SendMode Input
DetectHiddenWindows, On

window_name = BloodRayne
extra_border := 10

toggle := 0

go:
while(toggle == 1)
{
	IfWinExist, %window_name%
	{
		WinGetPos, w_x, w_y, w_w, w_h, %window_name%
		MouseGetPos, m_x, m_y
		max_x := w_x + w_w - 10 - extra_border
		max_y := w_y + w_h - 10 - extra_border
		if(m_x > max_x)
		{
			MouseMove, %max_x%, %m_y%
		}
		if(m_y > max_y)
		{
			MouseMove, %m_x%, %max_y%
		}
		w_y := w_y + extra_border
		if(m_y < w_y)
		{
			MouseMove, %m_x%, %w_y%
		}
		w_x := w_x + 10 + extra_border
		if(m_x < w_x)
		{
			MouseMove, %w_x%, %m_y%
		}
	}
}
return

F6::
if(toggle == 0)
{
	toggle := 1
	Goto, go
}
else
{
	toggle := 0
}
return
Friendlyrock
Posts: 2
Joined: 16 May 2018, 06:27

Re: Lock cursor to specific window

17 May 2018, 02:21

Qysh wrote:Hope this works ;)

F6 to toggle

Code: Select all

#NoEnv
#MaxHotkeysPerInterval 99000000
#HotkeyInterval 99000000
#MaxThreadsPerHotkey 255
#KeyHistory 0
ListLines Off
Process, Priority, , A
SetBatchLines, -1
SetKeyDelay, 0, -1
SetMouseDelay, -1
SetDefaultMouseSpeed, 0
SetWinDelay, -1
SetWorkingDir %A_ScriptDir%
SendMode Input
DetectHiddenWindows, On

window_name = BloodRayne
extra_border := 10

toggle := 0

go:
while(toggle == 1)
{
	IfWinExist, %window_name%
	{
		WinGetPos, w_x, w_y, w_w, w_h, %window_name%
		MouseGetPos, m_x, m_y
		max_x := w_x + w_w - 10 - extra_border
		max_y := w_y + w_h - 10 - extra_border
		if(m_x > max_x)
		{
			MouseMove, %max_x%, %m_y%
		}
		if(m_y > max_y)
		{
			MouseMove, %m_x%, %max_y%
		}
		w_y := w_y + extra_border
		if(m_y < w_y)
		{
			MouseMove, %m_x%, %w_y%
		}
		w_x := w_x + 10 + extra_border
		if(m_x < w_x)
		{
			MouseMove, %w_x%, %m_y%
		}
	}
}
return

F6::
if(toggle == 0)
{
	toggle := 1
	Goto, go
}
else
{
	toggle := 0
}
return
Well it does work how i asked and i do appreciate the help it really means a lot because i have been struggling with finding a solution to this problem for a while and it has been giving me a headache but now whenever the mouse would leave the screen but it can't because of the script running i can no longer turn that far which i doubt there is a solution for so i might go look for other solutions that aren't ahk but if there is a solution that uses ahk feel free to let me know :D

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 57 guests