Jump to content

Recommended Posts

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

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

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

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

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
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

    • By Synaps3
      I've recently been annoyed by how google images works. You can't click an image and see the full res image. You have to go to the website and find the image on the page and occasionally, it won't allow you to view the image easily. This script makes it easy to view any image in google images in full resolution immediately. You just press Ctrl + Q while hovering over the image you want and it'll open full res in a new tab. This is only tested in firefox, but it shouldn't be hard to modify for another browser.
      Here it is:
      #include <Misc.au3> #include <MsgBoxConstants.au3> #include <AutoItConstants.au3> #include <Clipboard.au3> #include <Array.au3> #include <String.au3> Local $clipB Local $urlArray Local $theLink HotKeySet("^q", "OpenImage") Func DecodeUrl($src) Local $i Local $ch Local $buff ;Init Counter $i = 1 While ($i <= StringLen($src)) $ch = StringMid($src, $i, 1) ;Correct spaces If ($ch = "+") Then $ch = " " EndIf ;Decode any hex values If ($ch = "%") Then $ch = Chr(Dec(StringMid($src, $i + 1, 2))) $i += 2 EndIf ;Build buffer $buff &= $ch ;Inc Counter $i += 1 WEnd Return $buff EndFunc ;==>DecodeUrl Func OpenImage() MouseClick($MOUSE_CLICK_RIGHT) Send("A") Sleep(100) $clipB = _ClipBoard_GetData($CF_TEXT) $theLink = DecodeUrl($clipB) $urlArray = _StringBetween($theLink, "=", "&") If StringInStr($urlArray[0], "?") <> 0 Then $urlArray = _StringBetween($theLink, "=", "?") EndIf ShellExecute($urlArray[0]) EndFunc While 1 Wend  
    • By Schuster
      Hey there,
      i need your help guys. I am working in the QA department of my company. A little part of or software produces hints (like little popups) which needs to be tested every release. I wrote scripts to trigger those hints and i also implemented the imagesearch.dll to find those hints on the screen. My goal now is it to let the machine work over night, so when i come back to work i only get a report which says 130/140 hints were found successfully. This already works, aslong as my pc is not locked, but i want/need to lock my pc because of security concerns.
      My general question. Is it possible to run my scripts on my locked PC and still find an image that i provide which will open sooner or later in the background?
       
      Thanks in advance
    • By PeterVerbeek
      This topic give you access to an AutoIt functions library I maintain which is called PAL, Peter's AutoIt Library. The latest version 1.19 contains 194 functions divided into these topics:
      window and screen mouse and GUI GUI controls logics and mathematics string, xml string and file string dialogues and progress bars data lists: lists, stacks, shift registers and key maps (a.ka. dictionaries) miscellaneous: logging/debugging, process and system info A lot of these functions were created in the development of Peace, Peter's Equalizer APO Configuration Extension, which is a user interface for the system-wide audio driver called Equalizer APO.
    • By topgundcp
      Hi, 
      This is my very first post in this forum and am also new with Autoit programming so be easy on me.
      Below is the code that I am trying to get the index of the item selected. No problem getting the text.
      Case $listEdition   ; handle of the list             local $index=0             $item=GUICTRLRead($listEdition)    ; This will return the text in the list             ; ==============   The loop below always fails  ==================             ; Meaning _GUICtrlListView_GetItemSelected($listEdition, $i) always return FALSE. WHY ???????              For $i = 0 To $editionArray[0] - 1   ; The content of the list in an array where editionArray[0] contains total count of items                 If _GUICtrlListView_GetItemSelected($listEdition, $i) Then                     $index = $i                     exitloop                 EndIf              Next              ;===================================================             ConsoleWrite( "Select Edition:     " & $item & "  index: " & $index & @CR) ....... Please look at the comments in the code & the pix attached.
      _GUICtrlListView_GetItemSelected($listEdition, $i) always returns FALSE.
      Another problem is on the list. It also populate  the total count of items from the Array. How can I skip this item from populating to the list ?.
      Please advise and thanks

    • By n0ktar
      is it possible to make a wall chams in rainbow six siege using autoit scripts? tell me please and how . 
×
×
  • Create New...