Jump to content
tiye0405

Getting distance in pixels?

Recommended Posts

tiye0405
Posted (edited)

Hello, 

 

I currently have a problem that deals with moving the mouse to a given location + or - a certain distance.

$search1 =_WaitForImageSearch("envelope.bmp", 10, 1, $x, $y, 20)
$search2 =_WaitForImageSearch("envelope2.bmp", 10, 1, $x, $y, 20)

 

If $search1 = 1 Then
            Sleep(100)
            MouseMove($x, $y, 10)
            sleep(99)
            MouseClick("left")
           Sleep(99)
ElseIf $search2 = 1 Then
           Sleep(100)
           MouseMove($x, $y2, 10)
           sleep(99)
           MouseClick("left")
           Sleep(100)
Else
          Sleep(150)
          MouseMove($x2, $y, 10)
          Sleep(150)
          MouseClick("left")
         Sleep(150)

EndIf

The problem about this is that i defined $x2 = $x - 175  and $y2 = $y + 35

I got these numbers ( 175 and 35) with the autoit helper and just subtracted point where it is to the point its supposed to move but it doesnt work.

is there any proper way to find the distance between 2 points in pixels?

 

Imgsearch doesnt always work for this picture so i want it to have a backup

 

edit: could it be that the definition of $x and $y  from the previous image search arent there anymore and thats why it moves my mouse to strange places? 
is there a way to preserve the $x $y from the previous img search untill the next succesful one?

 

 

Edited by tiye0405

Share this post


Link to post
Share on other sites
jchd
Posted (edited)

Old as he is Pythagoras is still your friend!

Looks like you're more after the correct origin for the coordinates than actual distance between pixels.

BTW why on earth do you need to compute mouse position this way? What are you trying to automete? There must be a more reliable way to perform thetask at hand.

Edited by jchd

This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites
tiye0405
Posted (edited)

edit:

Something must be off with my original text

my testing script works just fine going just where i want it to but my original script always goes to: ( current(x), 50) 

global $y = 0, $x = 0, $x2 = $x - 308, $y2 = $y + 40


$search1 =_WaitForImageSearch("name.bmp", 5, 1, $x, $y, 20)
$search2 =_WaitForImageSearch("star.bmp", 5, 1, $x, $y, 20)
If $search1 = 1 Then
    Sleep(100)
    MouseMove($x, $y, 10)
    sleep(99)
    MouseClick("left")
Sleep(99)
ElseIf $search2 = 1 Then
   Sleep(100)
    MouseMove($x, $y2, 10)
    sleep(99)
    MouseClick("left")
Sleep(100)
Else
Sleep(199)
$pos = MouseGetPos()
   Sleep(150)
   $x = $pos[0]
   $y = $pos[1]
    MouseMove( $x, $y - 1100, 10)
Sleep(150)
MouseClick("left")
Sleep(150))
EndIf

i cant find the problem of this specific script that doesnt work when my test ones do :/

 

 

i also tried 

Sleep(199)
$pos = MouseGetPos()
   Sleep(150)
    MouseMove( $pos[0], $pos[1] - 1100, 10)
Sleep(150)
MouseClick("left")
Sleep(150)

 

Edited by tiye0405

Share this post


Link to post
Share on other sites
badcoder123
Posted (edited)

Have you tried for loops? 

Example of script moving from bottom to top

For $i = @DesktopHeight To 0 Step - 1
    MouseMove(400, $i)
Next

 

36 minutes ago, tiye0405 said:

My problem is that no matter how much i subtract it always moves to the same spot.

 

Sleep(150)
$pos = MouseGetPos()
   Sleep(150)
    MouseMove($pos[0], $pos[1] - 50, 10)
Sleep(150)
MouseClick("left")
Sleep(150)

 

I want it to move a little higher than it already is and it works on the desktop but as soon as it's on google chrome it seems to go to the current xcoord and to the y coordinate that is supposed to be subtracted (in this case (x, 50)).

 

if you throw a while loop in the code like so it will work;

While 1
    Sleep(150)
    $pos = MouseGetPos()
    Sleep(150)
    MouseMove($pos[0], $pos[1] - 50, 10)
    Sleep(150)
    MouseClick("left")
    Sleep(150)
WEnd

I assume the reason why it always moves the mouse to the same spot is because you already have a loop running a series of mouse clicks and every time it gets to the line:

MouseMove($pos[0], $pos[1] - 50, 10)

it uses the previous mouse move location (not provided)... which won't work. If you provide more code I'm sure you can get an answer extremely quick

Edited by badcoder123

Share this post


Link to post
Share on other sites
tiye0405
Posted (edited)

Yes thank you for the quick reply, here is the whole code 

 

global $y = 0, $x = 0, $x2 = $x - 308, $y2 = $y + 40
HotKeySet("{NUMPAD2}", "Pause")
HotKeySet("{NUMPAD8}", "End")
Opt("MouseClickDownDelay", 30)
Global $Paused

#include <ImageSearch2015.au3>
#include <Misc.au3>

Func End()
   Exit
EndFunc

Func Pause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
     WEnd
  EndFunc
  
  
  Sleep(3000)
  $search1 = _WaitForImageSearch("Log.bmp", 30, 1, $x, $y, 10)
If $search1 = 1 Then
   Sleep(1000)
   Send("{ESC}")
  Sleep(200)
  Send("{ESC}")
  Sleep(3000)
  Send("{K}")
  sleep(100)
  EndIf
  
  
  $search1 = _WaitForImageSearch("TxtBar.bmp", 30, 1, $x, $y, 30)
If $search1 = 1 Then
    MouseMove($x, $y, 10)
    sleep(99)
    MouseClick("left")
    Sleep(100)
Sleep(100)
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{Enter}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Send("{x}")
Sleep(99)
Send("{Enter}")
Sleep(299)
EndIf

$search1 =_WaitForImageSearch("name.bmp", 5, 1, $x, $y, 20)
$search2 =_WaitForImageSearch("star.bmp", 5, 1, $x, $y, 20)
If $search1 = 1 Then
    Sleep(100)
    MouseMove($x, $y, 10)
    sleep(99)
    MouseClick("left")
Sleep(99)
ElseIf $search2 = 1 Then
   Sleep(100)
    MouseMove($x, $y2, 10)
    sleep(99)
    MouseClick("left")
Sleep(100)
Else
Sleep(199)
$pos = MouseGetPos()
   Sleep(150)
   $x = $pos[0]
   $y = $pos[1]
    MouseMove( $x, $y - 1100, 10)
Sleep(150)
MouseClick("left")
Sleep(150)

and i want it to continue afterwards just didnt get there yet

continue as in more imgsearches

Edited by tiye0405

Share this post


Link to post
Share on other sites
badcoder123
Posted (edited)
HotKeySet("{F1}", "myExit")

global $y = 0, $x = 0, $x2 = $x - 308, $y2 = $y + 40
HotKeySet("{NUMPAD2}", "Pause")
HotKeySet("{NUMPAD8}", "End")
Opt("MouseClickDownDelay", 30)
Global $Paused

#include <ImageSearch2015.au3>
#include <Misc.au3>

Func End()
   Exit
EndFunc

Func Pause()
    $Paused = NOT $Paused
    While $Paused
        sleep(100)
     WEnd
  EndFunc

While 1

    Sleep(3000)
    $search1 = _WaitForImageSearch("Log.bmp", 30, 1, $x, $y, 10)
    If $search1 = 1 Then
        Sleep(1000)
        Send("{ESC}")
        Sleep(200)
        Send("{ESC}")
        Sleep(3000)
        Send("{K}")
        sleep(100)
    EndIf


      $search1 = _WaitForImageSearch("TxtBar.bmp", 30, 1, $x, $y, 30)
    If $search1 = 1 Then
        MouseMove($x, $y, 10)
        sleep(99)
        MouseClick("left")
        Sleep(100)
        Sleep(100)
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{Enter}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Send("{x}")
        Sleep(99)
        Send("{Enter}")
        Sleep(299)
    EndIf

    $search1 =_WaitForImageSearch("name.bmp", 5, 1, $x, $y, 20)
    $search2 =_WaitForImageSearch("star.bmp", 5, 1, $x, $y, 20)
    If $search1 = 1 Then
        Sleep(100)
        MouseMove($x, $y, 10)
        sleep(99)
        MouseClick("left")
        Sleep(99)
    ElseIf $search2 = 1 Then
        Sleep(100)
        MouseMove($x, $y2, 10)
        sleep(99)
        MouseClick("left")
        Sleep(100)
    Else
        Sleep(199)
        $pos = MouseGetPos()
        Sleep(150)
        $x = $pos[0]
        $y = $pos[1]
        MouseMove( $x, $y - 1100, 10)
        Sleep(150)
        MouseClick("left")
        Sleep(150)
    EndIf

WEnd

Func myExit()
    Exit
EndFunc

Have you looked at While Loops in the help file?

Edited by badcoder123

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

  • Similar Content

    • nooneclose
      By nooneclose
      Good morning everyone, I thought I had already solved this issue but it turns out I did not. 
      My code finds unread emails with this specific subject line of "request" but when I change the subject to SKIPPED + "request" = ("SKIPPED request") the program still finds the email and tries to process it. I only want to process emails with the exact match subject of "request".
      Here is my code that "finds" the unread emails with the subject of "request" or so I thought. 
      Func ListUnreadEmails() ;******************************************************************************* ; Lists all unread E-mails from the folder Outlook-UDF-Test ;******************************************************************************* ; Stores all the unRead emails into an array Global $aItems = _OL_ItemFind($oOutlook, "*\Outlook-UDF-Test", $olMail, _ "[UnRead]=True", "Subject", "request", "EntryID,Subject", "", 1) ; Displays the array of unRead emails If IsArray($aItems) Then ;_ArrayDisplay($aItems, "OutlookEX UDF: _OL_ItemFind - Unread mails") Else MsgBox(48, "OutlookEX UDF: _OL_ItemFind Example Script", _ "Could not find an unread mail. @error = " & @error & ", @extended: " & @extended) EndIf ; Gets the number of unread emails Global $numberOfUnRead = UBound($aItems, $UBOUND_ROWS) - 1 ;MsgBox("", "Number of Unread emails", $numberOfUnRead) EndFunc It acts as if any part of the subject containing the word "request" and the email is unread that it will try to process it. (I think)
    • KhalidAnsari
      By KhalidAnsari
      Hi,
      I need to automate Java application using AutoIt, I have refer forum for the same, as per forum I am using Java Access Bridge to finding control name. But could not set value to control. Below is my sample code 
      Send("#r")
      sleep(1500)
      Send("D:\javaapplication\javaapplication\Hello.jar{Enter}")
      WinActivate("Penjumlahan")
      sleep(1500)
      ControlSetText("Penjumlahan", "", "Name:  A :", "demo")
      Java Application and Java Ferret screen

    • QaisBsharat
      By QaisBsharat
      Hello, 
      May i know how can i automation qt application?
      Using controlclick not mouse and positions
       
      Thanks
    • nooneclose
      By nooneclose
      Good afternoon, I am in need of some help. I am sure this is a stupid question requiring only one or two lines of code. However, I would greatly appreciate the help I cannot figure this out. I also tried searching for the answer on the internet but no one except me apparently seems to be having a hard time figuring this out and or is asking about it. 
      I simply want to change the "status" of an email from unread to read once I have processed it. My code is over 500 lines and I would like not to clutter this post with it. Assume I have all my includes and connections properly defined and stuff. 
      Here is the bit of code where I am trying to change the email that was used from unread to read:
      Func ChangeEmailStatus() ;******************************************************************************* ; changes the status of an email from unread to Read ;******************************************************************************* Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (Before Change)", $iRows) _OL_ItemModify($oOutlook,$aItems[$i][0], Default, "Read=True") MsgBox("", "Array Display 1", $aItems[1][0]) MsgBox("", "Array Display 2", $aItems[2][0]) Local $iRows = UBound($aItems, $UBOUND_ROWS) MsgBox("", "Number of Unread emails (After Change)", $iRows) EndFunc  
    • SharpDressedMan
      By SharpDressedMan
      Hello,
      Is there any way to check for validity of a pointer to a DllStruct ?
      In the above code, a DllStruct is created from an invalid pointer. How to prevent from doing this ?
      local $tStruct = DllStructCreate("int i") DllStructSetData($tStruct, "i", 123) local $pStruct = DllStructGetPtr($tStruct) $tStruct = 0 ; destroy DllStruct ==> $pStruct becomes invalid ; how to check here for validity of $pStruct and prevent from doing the following ? $tStruct = DllStructCreate("int i", $pStruct) ; create DllStruct from invalid pointer... MsgBox(0, @ScriptName, @error) ; displays '0' : invalid pointer is not detected by DllStructCreate() MsgBox(0, @ScriptName, IsDllStruct($tStruct)) ; displays '1' : tStruct is assumed as a valid DllStruct object, which is not Thanks for help
×