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

    • Pagi
      By Pagi
       
      <a href="index.php=4143b27b41db0a40c499202865c3e24d" class="menuitem " target="\_self"> "Menu Item 1" </a>
      Can you tell me if it´s possible to click this menu button? If yes, how? Cause I have no idea, I think i should use _IETagNameGetCollection
    • mar3011
      By mar3011
      hello, I want to set in the inputbox field random key from the keyboard to which the function will be assigned, for example F4 function start notepad ALT + A function start notepad for one function. Thank you for any help.  
    • JuanFelipe
      By JuanFelipe
      Cambiar a español Hello friends, I need help with a problem I have, I want to know if there is any way to update a GUI already running, that is I have a GUI of a certain size and with a button I would like to enlarge it:
      example: $ form1 = GUICreate ("", 200,100,0,0)   When you press the button, the gui increases its size, and actuates the new size.
    • BogdanNicolescu
      By BogdanNicolescu
      While 1 / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / WEnd OR:

       
      HotKeySet("{ESC}", "Terminate") While 1 MouseClick("Right",674,422) MouseClick("Left",673,447) Sleep(2000) / / / A whole bunch of codes found in help and here: https://www.autoitscript.com/autoit3/docs/ / / / MouseClick("Left",675,339) SLeep(3000) WEnd Func Terminate()     Exit 0 EndFunc  
      Sorry if i should't let this here to be found by newbies like me -.-'
    • santoshM
      By santoshM
      Dear friends i am facing a problem , i have created a window in autoit some time it is moving with the mouse curser even if iam not clicking the window 
×