pixelsearch in middle of screen/monitor? - autohotkey

i wanted to afk or have some break while leveling my character,the green box are the monster yea i messed around inside game files and edited it with photoshop lol,
my script is doing perfectly fine and attacking monster, but how can I make pixelsearch/attack only in the middle screen? to avoid my character from deaths. It doesn't work i dont know why. can you suggest me what's wrong?
CoordMode, Pixel, Relative
SetMouseDelay, -1
Home:: press home to start
;assuming to search in a reactangle area 200x200px
leftBound := A_ScreenWidth / 2 - 100
rightBound := A_ScreenWidth / 2 + 100
topBound := A_ScreenHeight / 2 - 100
bottomBound := A_ScreenHeight / 2 + 100
Loop {
PixelSearch, X, Y, leftBound, topBound, rightBound, bottomBound, 0x00FF00, 0, fast
if(ErrorLevel=0)
{
MouseClick, left, %X%, %Y%
}
else {
Send {F9}
sleep, 50
}
}
return
PgUp::Pause
End::ExitApp

You need to put the variables into percent signs %:
PixelSearch, X, Y, %leftBound%, %topBound%, %rightBound%, %bottomBound%, 0x00FF00, 0, fast
Also see the documentation for details:
For X1,Y1, it says:
The X and Y coordinates of the upper left corner of the rectangle to search
By "coordinates", obviously a number is described. This means, that in this case, you need to state a value and not variable's name. The values are stored inside the variables, so use the percent signs to access the variable content.

Related

Having problem with pixelgetcolor within loop and would be open to any suggestion

This is my code. What i want to do, is this loop to finish what its doing when i find this this color.
I belive the problem is with the cordinates from pixelgetcolor, i have no idea how to put cordinates there. Iv tried with pixelsearch and it wasnt a succes either.Do you have any suggestion what should i do ? The idea is to click non-stop unless this color is on the screen.
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
Loop ; This loop do non stop, unless the color is on the screen.
{
MouseMove, %X%, %Y%
Click
sleep,%flick%
Click
sleep,%flick1%
PixelGetColor,Dead_Monster,X,Y,RGB
if(Dead_Monster = 0x3CC4C4)
{
break ΒΈ
}
}
You need to wrap your variables in % for PixelGetColor to use the value of those variables. Also, your variables X and Y are never set anywhere...
CoordMode, Mouse, Screen
CoordMode, Pixel, Screen
; initial values?
X := 800
Y := 600
Loop ; This loop do non stop, unless the color is on the screen.
{
MouseMove, %X%, %Y%
Click
sleep,%flick%
Click
sleep,%flick1%
PixelGetColor,Dead_Monster,%X%,%Y%,RGB
if(Dead_Monster == 0x3CC4C4){
break
}
; insert line here to update X, Y ?
}
If you're looking to search the screen for a pixel, you can do the following:
; Modified example from https://www.autohotkey.com/docs/commands/PixelSearch.htm
Dead_Monster := 0x3CC4C4
;Search rectangle
S_Left := 0
S_Top := 0
S_Bottom := A_ScreenHeight
S_Right := A_ScreenWidth
PixelSearch, Px, Py, %S_Left%, %S_Top%, %S_Bottom%, %S_Right%, %Dead_Monster%, 3, Fast
if ErrorLevel
MsgBox, That color was not found in the specified region.
else
MsgBox, A color within 3 shades of variation was found at X%Px% Y%Py%.
However, I don't recommend searching the whole screen area as the search time increases greatly with larger search areas.

Autohotkey get width of current active child window

I am trying to write a script that moves mouse cursor to the center of active child window.
WinGetActiveStats, Title, Width, Height, X, Y
MouseMove, Width / 2, Height / 2, 0
Above does the trick for the Main window. However, I can't seem to find a way to grab the width and height of active child window so that I can move the mouse cursor to the center of child window.
This is very useful feature when using with softwares such as AutoCAD where you could have more than one child window open at any given moment.
Thanks,
The following should work:
ControlGetFocus, cr, A ; get the focused(active) control(child window) of the active window
ControlGetPos, x, y, width, Height, %cr%, A ; get the position and dimensions of this control
MouseMove, % x + Width / 2, % y + Height / 2, 0

MouseMove doesn't seem to work

I made a (working) auto clicker and I wanted to add a little modification to it.
I want the code to grab the mouse's current position when you call the AutoClick function. Now when it calls the ClickClick function it gets the now current position of the mouse. After that, it snaps the mouse back to the original position (oX, oY) and clicks. After clicking, it jumps to the position the mouse was just at (x, y). The clicking part works, but the mouse doesn't move at all.
I have no idea what to do to try to fix it.
^h::AutoClick()
^j::ExitApp
AutoClick(Interval=100){
MouseGetPos, xpos, ypos
oX = %xpos%
oY = %ypos%
static Toggler
Toggler := !Toggler
TPer := Toggler ? Interval : "off"
SetTimer, ClickClick, %TPer%
return
ClickClick:
BlockInput On
MouseGetPos, x, y
MouseMove, %oX%, %oY%, 0
Click
MouseMove, %x%, %y%, 0
BlockInput Off
return
}
Fistly, you have some restructuring you need to take care of- Get your Timer's subroutine out of the function. It doesn't belong there; plus it won't be isolated to the function anyway because it's global.
The oX, oY variables are in fact isolated to the function and are therefore only available within that function. Unless you declare them as global.
oX:=oY:=""
^h::AutoClick()
^j::ExitApp
AutoClick(Interval=100){
global oX, oY
static Toggler
MouseGetPos, xpos, ypos
oX = %xpos%
oY = %ypos%
Toggler := !Toggler
TPer := Toggler ? Interval : "off"
SetTimer, ClickClick, %TPer%
return
}
ClickClick:
BlockInput On
MouseGetPos, x, y
MouseMove, %oX%, %oY%, 0
Click
MouseMove, %x%, %y%, 0
BlockInput Off
return
Alternatively, you can have your function return a value (in this case mouse coords) and pass those back to your ClickClick.

how to setup pixelSearch only in middle of window mode screen

im playing ragnarok using macro.. my script is doing good.. but how can i pixelsearch/attack only the middle area? im using 1024 x 768 game window mode, using the CoordMode, Pixel, Relative
CoordMode, Pixel, Relative
CoordMode, Mouse, Relative
Home:: ;click home to start
Loop {
PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%, 0x00FF00, 0, fast ;<--- this is the color of green boxed monsters to attack
if(ErrorLevel=0) {
MouseClick, left, %X%, %Y%
}
else {
Send {F1} ; <--- if no monster present in screen, press teleport to search monsters
}
}
return
PgUp::Pause
End::ExitApp
As I commented in your previous question:
0, 0, %A_ScreenWidth%, %A_ScreenHeight% are coordinates. Replace these with any nubers (preferably with any variable contents) you like. Measure your exact coordinates with with WindowSpy. Open WindowSpy by right-clicking on any AHK script in the taskbar and selecting it. I suggest you then also take a look at coordmode.
Documentation says:
PixelSearch, OutputVarX, OutputVarY, X1, Y1, X2, Y2, ColorID [, Variation, Fast|RGB]
X1, Y1 The X and Y coordinates of the upper left corner of the rectangle to search
X2, Y2 The X and Y coordinates of the lower right corner of the rectangle to search
You are using: PixelSearch, X, Y, 0, 0, %A_ScreenWidth%, %A_ScreenHeight%. So, the coordinates of your selected rectangle's upper left corner are 0|0 and the lower right corner's are %A_ScreenWidth%|%A_ScreenHeight%. Let's assume your screen is 1366 pixels broad and 768 pixels wide. Then, the coordinates of the lower right corner are 1366|768.
You can replace these numbers with anything you like, for example
PixelSearch, X, Y, 300, 100, 600, 200, 0x00FF00, 0, fast
, or preferably
upperLeftX := 300
upperLeftY := 100
lowerRightX := 600
lower RightY := 200
PixelSearch, X, Y, %upperLeftX%, %upperLeftY%, %lowerRightX%, %lowerRightY%, 0x00FF00, 0, fast
(which is the same as above),
where 300|100 are the coordinates of the upper left corner and 600|200 the coordinates of the lower right corner for PixelSearch to search for your Pixel in. Determine the coords of your preference with WindowSpy.

Snap mouse cursor to center of screen

When F4 is pressed I'm attempting to snap the cursor to center of screen. Here is what I'm trying :
F4::
x := (A_ScreenWidth / 2)
y := (A_ScreenHeight / 2)
mousemove, x, y
return
But when I run this script the mouse position moves on opening and when press F4 the mouse does not moves position ?
Try this:
#Persistent ;//keeps script running
CoordMode, Mouse, Screen
Return ;//stops auto execution
F4:: ;//your code
x := (A_ScreenWidth / 2)
y := (A_ScreenHeight / 2)
mousemove, x, y
return
Without #Persistent, script would close after executing all the lines of code.
Autohotkey executes every line of code until the first "Return".
CoordMode line will ensure the mouse movement is relative to the screen as opposed to the active window (credit: #user3419297)
Toodles
F4::
CoordMode, Mouse, Screen ; If this command is not used, the coordinates are relative to the active window.
x := (A_ScreenWidth / 2)
y := (A_ScreenHeight / 2)
mousemove, x, y
return
http://ahkscript.org/docs/commands/CoordMode.htm#Remarks
Nircmd by Nir Sofer has the following option:
nircmd setcursor x y
You can create a shortcut to this command line and assign any hotkey to it. There are a lot of other options for mouse cursor as detailed in the nircmd.chm file.