 |
AutoHotkey Community Let's help each other out
|
| View previous topic :: View next topic |
| Author |
Message |
Jaws87
Joined: 21 Nov 2009 Posts: 4
|
Posted: Sat Nov 21, 2009 1:06 am Post subject: Beginner looking for some help with pixel detection. |
|
|
First post on the boards. I've read everything that popped up through search relating to what I am trying to do and no luck. What I am trying to do is use pixel detection to lock on to the pixel that I am currently hovering over. In other words I am trying to search a small box in the middle of my screen instead of my entire window. This should stay locked until I release the key. Here is the part giving me trouble:
~F3::
MouseGetPos, begin_x, begin_y
while GetKeyState("F3")
{
MouseGetPos, x1, y1
PixelSearch, Px, Py, 0, 0, 636, 638, %color%, 0, Fast
if ErrorLevel
MsgBox, That color was not found in the specified region.
else
MouseMove, Px, Py, 0 ;0 is mouse speed, 0 is instant
}
Return
I am new to the lang so go easy on me. Thanks in advance!
-Jaws87 |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 401
|
Posted: Sat Nov 21, 2009 3:36 am Post subject: |
|
|
Can you give more info? Im a little puzzled in what your trying to do. You want to lock-on to a pixel? What do you mean by that?
Also use the MouseGetPos cords with the PixelSearch region if thats what your looking for. |
|
| Back to top |
|
 |
Jaws87
Joined: 21 Nov 2009 Posts: 4
|
Posted: Sat Nov 21, 2009 3:44 am Post subject: |
|
|
Ok this is what I have done so far. It works but just not like I had hoped. I don't believe there is much more I can do to make it work with the apps that I am trying. But it is flawless when using it in paint.
F1::
{
IniFile := "C:\Users\Jesse\Desktop\location.txt"
FileGetSize, size, %IniFile%
if (size = "") {
MsgBox Setting up
IniWrite, %color%, %IniFile%, location, color
} else {
IniRead, %color%, %IniFile%, location, color
}
CoordMode, Pixel
Return
}
F2::
{
MouseGetPos, x, y
PixelGetColor,color, %x%, %y%
IniWrite, %color%, %IniFile%, location, color
Return
}
~F3::
MouseGetPos, begin_x, begin_y
while GetKeyState("F3")
{
MouseGetPos, x1, y1
PixelSearch, Px, Py, 803, 524, 803, 524, %color%, 0, Fast
MouseMove, Px, Py, 0 ;0 is mouse speed, 0 is instant
}
Return
f1: creates ini file if there isn't one.
f2: selects the pixel to lock to.
Hold f3: goes to the pixel and stays on it until you let off.
I was hoping to use it in some simple flash games etc. as a means of aiming. It was a good beginner project but I just don't think PixelSearch can process it.
If you have any suggestions let me know. |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 401
|
Posted: Sat Nov 21, 2009 4:04 am Post subject: |
|
|
Theres much better way to do stuff like this. First i wouldnt use GetKeyState.
You know there is also a PixelMatrixSearch right? Search the forum.
Basically it searchs or obtains a 3x3 matrix be default.. Meaning. a combination of 3x3 pixels so its uniqe. That way it wont mis-match as much.. or maybe not at all |
|
| Back to top |
|
 |
Jaws87
Joined: 21 Nov 2009 Posts: 4
|
Posted: Sat Nov 21, 2009 4:17 am Post subject: |
|
|
| PixelMatrixSearch seems to be pretty advanced from the examples posted on here. I'll read up on it tommorow and modify/test it. Thanks for the support, i'll keep posting here with the changes I make. |
|
| Back to top |
|
 |
i3egohan
Joined: 18 Jul 2006 Posts: 401
|
Posted: Sat Nov 21, 2009 4:21 am Post subject: |
|
|
| It actually isnt complicated at all. 2 functions. One finds the matrix. One obtains the matrix. Just call them when you need to. |
|
| Back to top |
|
 |
Jaws87
Joined: 21 Nov 2009 Posts: 4
|
Posted: Sun Nov 22, 2009 3:48 am Post subject: |
|
|
I have made the changes and implemented PixelMatrixSearch. Seems to work on a screen cap of the game but not in the game itself?
Here is what I've got:
#NoEnv
#SingleInstance Force
#Persistent
SetBatchLines -1
SetDefaultMouseSpeed, 0
SetControlDelay, -1
Process,priority,,low
SetBatchLines, -1
CoordMode, Pixel, Screen
CoordMode, Mouse, Screen
f1::
MouseGetPos, mX, mY
SplashImage, Off
Matrix := GetMatrix(mX,mY,4)
Matrixtemp := Matrix
again:
soundbeep 3000
Result := FindMatrix(1,1600,1,1200,4,Matrix)
~f2::
MouseGetPos, begin_x, begin_y
while GetKeyState("f2")
{
Result := FindMatrix(1,1600,1,1200,4,Matrix)
StringSplit, Result, Result, %A_Space%
Mousemove, %Result1%, %Result2%
}
Return
f3:: reload
Once again, I am open to any suggestions. Thanks. |
|
| Back to top |
|
 |
|
|
You can post new topics in this forum You can reply to topics in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|