Sign in to follow this  
Followers 0
Sori

Why is the mouse moving?

6 posts in this topic

#1 ·  Posted (edited)

You might remember helping me with my previous topic:

This is essentially a continuation of that. I have an odd glitch going on with it.

 

Running this code:

$returnValue = AdvancedImageSearch("Trash Can.bmp", 20, 0)
MsgBox(0, "Returned", $returnValue)

I am using a screenshot of the recycle bin as the tester.

If the recycle bin is in the top left corner of the screen

I will receive "Returned 0"

This is because the mouse will move to the top left of the screen some time before the search executes, and will obstruct the search.

If the recycle bin is in another location, then it will return 1. But the mouse will still move to the top left corner.

Running this code:

$returnValue = AdvancedImageSearch("Trash Can.bmp", 20, 1)
MsgBox(0, "Returned", $returnValue)

It does not matter where the recycle bin is. The program will correctly find it, and place the mouse cursor in the center of the recycle bin.

;~ AdvancedImageSearch(ImageName, ErrorRate, MoveMouseTo)
;~ AdvancedImageSearchOneShot (Only checks last known location)
;~ returns 1 if image found
;~
;~ Saves image location to
;~ HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations "Last Found X"
;~ And
;~ HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations "Last Found Y"


#include <GetFileProperty.au3>
#include-once <ImageSearch.au3>

Dim $pHeight = 0
Dim $pWidth
Dim $dArray
Dim $lastKnownX = ""
Dim $lastKnownY = ""
Dim $checkXTL = 0
Dim $checkXBR = 0
Dim $checkYTL = 0
Dim $checkYBR = 0

;Searches for the image by checking the last known location first, then by looking at entire screen.
;Then stores this data for future useage.
Func AdvancedImageSearch($picName, $transparency, $moveMouseTo)
    Dim $x = 0
    Dim $y = 0
    If FileExists("D:\AI\Images\" & $picName) = 1 Then ;Make sure the image exists
        If RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Width") = "" Then ;Check if the image has saved dimensions
            GetDimensions($picName)
        Else
            $pWidth = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Width")
            $pHeight = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Height")
        EndIf
        $lastKnownX = GetLastX($picName) ;Obtain the X coordinates of the image
        $lastKnownY = GetLastY($picName) ;Obtain the Y coordinates of the image

        ;If no record of File exists, search entire screen and save location found to registry.
        If $lastKnownX = "" Then
            If _ImageSearchArea("*Trans0xFF00FF D:\AI\Images\" & $picName, 1, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $transparency) = 1 Then
                RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " X", "REG_SZ", $x)
                RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Y", "REG_SZ", $y)
                SetLocationCoordinates($picName)
                RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", "Last Found X", "REG_SZ", $x)
                RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", "Last Found Y", "REG_SZ", $y)
                If $moveMouseTo = 1 Then
                    MouseMove($x, $y, 0) ;Move mouse to image, if the user selected this option
                EndIf
                Return "1"
            Else
                Return "0"
            EndIf
        Else
            ;If a record of the image exists, check last known location.
            If RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXTL") = "" Then
                SetLocationCoordinates($picName) ;Set the search parameters if no previous data
            Else
                $checkXTL = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXTL")
                $checkXBR = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXBR")
                $checkYTL = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkYTL")
                $checkYBR = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkYBR")
            EndIf
            If _ImageSearchArea("*Trans0xFF00FF D:\AI\Images\" & $picName, 1, $checkXTL, $checkYTL, $checkXBR, $checkYBR, $x, $y, $transparency) = 1 Then
                RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", "Last Found X", "REG_SZ", $x) ;Store the X location of the image
                RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", "Last Found Y", "REG_SZ", $y) ;Store the Y location of the image
                If $moveMouseTo = 1 Then
                    MouseMove($x, $y, 0) ;Move mouse to image, if the user selected this option
                EndIf
                Return "1" ;Return 1 to show that the image was found.
            Else
                ;If not found at last location, check entire screen.
                If _ImageSearchArea("*Trans0xFF00FF D:\AI\Images\" & $picName, 1, 0, 0, @DesktopWidth, @DesktopHeight, $x, $y, $transparency) = 1 Then
                    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " X", "REG_SZ", $x)
                    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Y", "REG_SZ", $y)
                    $lastKnownX = GetLastX($picName)
                    $lastKnownY = GetLastY($picName)
                    SetLocationCoordinates($picName)
                    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", "Last Found X", "REG_SZ", $x)
                    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", "Last Found Y", "REG_SZ", $y)
                    If $moveMouseTo = 1 Then
                        MouseMove($x, $y, 0) ;Move mouse to image, if the user selected this option
                    EndIf
                    Return "1"
                Else
                    Return "0"
                EndIf ;Search entire screen
            EndIf ;Found at Last Coordinates
        EndIf ;Last Known X
    Else
        ;Image file does not exist
        MsgBox(0, "File Path Error", "Picture: '" & $picName & "' does not exist in Images folder.")
    EndIf ;File Exists
EndFunc   ;==>AdvancedImageSearch

;Searches for the image only using the stored information.
Func AdvancedImageSearchOneShot($picName, $transparency, $moveMouseTo)
    Dim $x = 0
    Dim $y = 0
    If FileExists("D:\AI\Images\" & $picName) = 1 Then ;Make sure the image exists
        $lastKnownX = GetLastX($picName) ;Obtain the X coordinates of the image
        $lastKnownY = GetLastY($picName) ;Obtain the Y coordinates of the image

        ;Set coordinates to search
        $checkXTL = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXTL")
        $checkXBR = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXBR")
        $checkYTL = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkYTL")
        $checkYBR = RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkYBR")

        ;Search for the image using saved data
        If _ImageSearchArea("*Trans0xFF00FF D:\AI\Images\" & $picName, 1, $checkXTL, $checkYTL, $checkXBR, $checkYBR, $x, $y, $transparency) = 1 Then
            If $moveMouseTo = 1 Then
                MouseMove($x, $y, 0) ;Move mouse to image, if the user selected this option
            EndIf
            Return "1" ;Return 1 to show that the image was found.
        Else
            Return "0" ;Return 0 if image is not found
        EndIf
    Else
        ;Image file does not exist
        MsgBox(0, "File Path Error", "Picture: '" & $picName & "' does not exist in Images folder.")
    EndIf ;File Exists
EndFunc   ;==>AdvancedImageSearchOneShot

;Obtains and stores dimensions of image
Func GetDimensions($picName)
    Dim $prop
    $path = "D:\AI\Images\" & $picName
    $prop = _GetFileProperty($path, "Dimensions")
    $dArray = StringSplit($prop, " x ")
    $pWidth = Number(StringMid($dArray[1], 2))
    $pHeight = Number($dArray[4])
    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Width", "REG_SZ", $pWidth)
    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Height", "REG_SZ", $pHeight)
EndFunc   ;==>GetDimensions

;Returns last known X location of image
Func GetLastX($picName)
    Return RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " X")
EndFunc   ;==>GetLastX

;Returns last known Y location of image
Func GetLastY($picName)
    Return RegRead("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " Y")
EndFunc   ;==>GetLastY

;Saves search parameters of picture for use with fast search.
Func SetLocationCoordinates($picName)
    $checkXTL = $lastKnownX - (Round(($pWidth / 2)) + 1)
    $checkXBR = $lastKnownX + (Round(($pWidth / 2)) + 1)
    $checkYTL = $lastKnownY - (Round(($pHeight / 2)) + 1)
    $checkYBR = $lastKnownY + (Round(($pHeight / 2)) + 1)
    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXTL", "REG_SZ", $checkXTL)
    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkXBR", "REG_SZ", $checkXBR)
    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkYTL", "REG_SZ", $checkYTL)
    RegWrite("HKEY_CURRENT_USER\Software\AdvancedImageSearch\Image Locations", $picName & " checkYBR", "REG_SZ", $checkYBR)
EndFunc   ;==>SetLocationCoordinates
Edited by Sori

If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

just forget it did not understand question correctly but it shud not mousemove if your calling last parametar as something diffrent than 1. you do have  If $moveMouseTo = 1 Then and after that Return "1", so mouse shud move only if moveMouseTo is 1 in the part of script that after it return "1"
 
 
if your not running script from scite run it from scite just to be safe from the side that your starting script that your editing.
Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

The mouse will go to the top left corner of the screen, essentially (0, 0)

If I tell the mouse to move, by giving the last parameter as a 1 then it will move to the center of the picture, as it is supposed to do.

It will not move to the corner.

If the program is unable to find the picture, it will still move the mouse to the corner of the screen.


If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Use msgbox or consolewrite in every location where $x and $y might change. my guess is it hits the mousemove($x,$y,0) line and x and y both = 0 at that point for whatever reason.

If you log all your changes to those variables so you can physically see them changing, you can narrow down where the error is coming from.

*edit*

also check your $mousemoveto flag to see if it gets unexpectedly changed somewhere

Edited by kaotkbliss

010101000110100001101001011100110010000001101001011100110010000

001101101011110010010000001110011011010010110011100100001

My Android cat and mouse game
https://play.google.com/store/apps/details?id=com.KaosVisions.WhiskersNSqueek

We're gonna need another Timmy!

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

can you write down the part of code that shud tell the script

If the program is unable to find the picture, it will still move the mouse to the corner of the screen.


Think i (or we) did not usnderstand the problem correctly, can you answer one more time

1. what your code shud do?
(example mu cude shud move mouse only on return '1')

2. what your code is dooing diffrent of what it shud do?
(example my code move mouse move even if it return '0')

Edited by bogQ

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

The code is supposed to make image searching much faster.

It saves location and size information of an image that it finds. If the program has to look for the same image again, it will check in the last location that it had found the image. If the image has not moved, this is a significant increase in find speed.

There are 2 main functions of the program. essentially: find image, and find image one-shot.

Find image will check the last known location, then if the image is not found; it will check the entire screen, and save new parameters.

One-shot will only check the last parameters and then give up.

You also have an option that you can have the mouse move to the center of the image, upon finding it.

---

What the code is supposed to do:

Let's say you put a msgbox to display the return value.

You run the code opting not to move the mouse.

It will find the image and msgbox 1 to you.

or

It will not find the image, and it will msgbox 0 to you.

 

What the code is doing:

You run the code opting not to move the mouse.

It will find the image, move the mouse to the upper left corner of the screen, then msgbox 1.

or

It will not find the image, move the mouse to the upper left corner of the screen, then msgbox 0.

You run the code opting to move the mouse to the image.

It will find the image, move the mouse to the center of the image, and msgbox 1

The mouse will remain in the center of the image.

---
Doing research on it:

I placed a msgbox before the variable to move the mouse.

It showed correctly that the variable was 0.

I placed a msgbox inside the if statement.

This message box never went off (showing that the program did not move the mouse by my command)

If the image is in the top left corner of the screen...

When you tell it to find the image. The mouse will move to the corner. Then the message box will display a 0, as in it could not find the image. Therefore, the mouse is being moved at sometime before the image search begins.


If you need help with your stuff, feel free to get me on my Skype.

I often get bored and enjoy helping with projects.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0