HELP ADVANCED AHK CODE

Ask gaming related questions (AHK v1.1 and older)
Gonzalo94
Posts: 40
Joined: 17 Jul 2017, 12:56

HELP ADVANCED AHK CODE

19 Jan 2018, 17:47

Hello.

I have a problem, regarding a game called OS-Scape: https://os-scape.com/
In the bottom-right corner part of screen and during game play there's an area within which one can find up to 4x6 items: 6 per row, 4 by columns.
I also made a script that does the folowing: if I press LButton and until I released it, it spams LButton.
If I press CTRL+LButton it does the same as the previous one except for the items which immediatly surrond the item (first at the left, the right, the top, the bottom, if any)
which was first cliked.
My question is: Is there any awy to avoid the need to use two hotkeys and use only one instead?
By the way, I already think about a solution that runs the subroutine associated with the LButton key combination or the CRTL+Lbutton one depending on whether or not the very item
itself was clicked or the grey area immediatly surronding it in order to avoid the need of two hotkeys. Unfortunately, it appears that the grey-black background of the area is not homogeneous...
use PixelGetColor the moment the hotkeys fires cannot provide any help...
Any ideas?

My Script:

Code: Select all

CoordMode, Mouse, Window
SetTitleMatchMode, 2
#NoEnv
Process, Priority,, H
#MaxHotkeysPerInterval 10000
#MaxThreadsPerHotkey, 10000
SetMouseDelay, -1
SetKeyDelay, 0
SetWinDelay, 0
SetControlDelay -1
ListLines, Off


centers := {rows: [ 225,260,295,330,370,400 ], colums: [ 580,622,667,710 ]}

#IfWinActive OS-Scape
$^LButton::
$LButton::
~LShift & LButton::
MouseGetPos, x, y
if (Between(550, 740, x) and Between(205, 460, y)) {
	if !(A_ThisHotkey = "$^LButton") {
		While (GetKeyState("LButton", "P")) {
                if (GetKeyState("Ctrl")) {
			continue
                        }
			click
			  Sleep 15
		}
	} else {
		calculateCenter(rcstart, ccstart)
		While (GetKeyState("LButton", "P")) {
			calculateCenter(rc, cc)
			if (Between(34, 38, Abs(rcstart-rc)) or (Between(35, 45, Abs(ccstart-cc)))) {
					continue
			}
				click
				  Sleep 15
		}
	}
} else send, {LButton}
return
#If
F10::Suspend, On
F7::Suspend, Off


Between(lowerBound, upperBound, var) {
If var between %lowerBound% and %upperBound%
	return true
return false
}
calculateCenter(ByRef rcs:="", ByRef ccs:="") {
global
	MouseGetPos, x, y
	for index, center in centers.rows, o := []
		o[ Abs(y-center) ] := center
	rcs := o[o.minIndex()]
	for index, center in centers.colums, o := []
		o[ Abs(x-center) ] := center
	ccs := o[o.minIndex()]
	return true
}
What it does: once LButton/CTRL+LButton is clicked if first check if the mouse is over the area where are located
all the items using MouseGetPos, if it is it execute statements depending one the value of A_ThisHotkey. In particuluar
if the hotkey is CTRL+LButton it calculate the center of the item beneath the mouse upon click using the calculateCenter function
and spams while subsequent calls of this function returns values that does not imply that the absolute distance (calculated by using Abs
function) is not the one that represent the area imediatly surronding teh item which was first clicked.


Thanks
Attachments
jaosjkakms.png
jaosjkakms.png (40.44 KiB) Viewed 525 times
User avatar
eventhorizon
Posts: 158
Joined: 27 Oct 2016, 14:22

Re: HELP ADVANCED AHK CODE

19 Jan 2018, 18:12

One way you might think of it is that each item in the picture is centered at some xy location on the screen. Given that there are 28 items you would need 28 xy coordinate pairs to classify all the icons one of which will uniquely identify a specific item. Knowing where the mouse is using the "MouseGetPos, command will allow you to find out precisely where the mouse in in the current window and the MouseMove, command will allow you to go to a specific xy location to click. Hope this helps...
A computer lets you make more mistakes faster than any invention in human history – with the possible exceptions of handguns and tequila.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: yuu453 and 68 guests