Sign in to follow this  
Followers 0
skyinthesea

Quick questions from a complete newbie!

5 posts in this topic

Hey guys, I downloaded Autoit around 4 days ago. Having watched some tutorials and tried out a few things I have a few questions.

If I'm making a simple script that clicks in certain x/y co-ordinates, how can I make this be used on my laptop that has a different resolution. For example my monitor resolution is 2048x1152 but my laptop is

1680x1050.

- Is it possible to make mouse movements and clicks as a %? For example:

MouseMove(1024, 576)
MouseClick ("left")

So something like Mousemove(50%,50%).

My second question is, how do I make this into a loop?

;looking for blue things!
$pixel = PixelSearch(0, 0, 2048, 1152, 0x6969FF)
If IsArray($pixel) = True Then
MouseMove ($pixel [0], $pixel [1], 1)
MouseClick ("left")
Sleep(900)
EndIf

I want it to keep checking until there is no more, then search for yellow instead:

;looking for yellow things!
$pixel = PixelSearch(0, 0, 2048, 1152, 0xFFFF00)
If IsArray($pixel) = True Then
MouseMove ($pixel [0], $pixel [1], 1)
MouseClick ("left")
Sleep(900)
EndIf

Thanks in advance!

Share this post


Link to post
Share on other sites



Hi skyinthesea,

To move the mouse by a percentage, you'll have to calculate that yourself. The macros @DesktopWidth and @DesktopHeight will help you out with that. For example:

Local $x = 50, $y = 50
MouseClick("primary", $x * @DesktopWidth / 100, $y * @DesktopHeight / 100)

Set $x and $y to whatever percents you want to use.

To make it loop, you can do something like this:

While 1 ; This will always be true, so it will loop between While/WEnd forever
$pixel = PixelSearch(0, 0, 2048, 1152, 0x6969FF)
If Not @error Then
  MouseClick("primary", $pixel[0], $pixel[1])
  Sleep(900)
Else
  ExitLoop ; This will break out of the While/WEnd loop
EndIf
WEnd

Share this post


Link to post
Share on other sites

Hi, skyinthesea, welcome to the forum. There are a couple of ways to do what you would like. What app are you trying to automate? There may be ways to click on the window based on how it is created in the application that could be easier than trying to use mouse coords.


√-1 2^3 ∑ π, and it was delicious!

Share this post


Link to post
Share on other sites

I agree with JLogan, I started out using X and Y coordinates but quickly realized there would be issues and unknowns. I recommend ControlClick or ControlSetText commands. You can find the controls using the AutoIT Window Info applet.

Share this post


Link to post
Share on other sites

#5 ·  Posted (edited)

Hi! Thanks so much for the replies, Artisan your scripts worked a charm!

My next question is, can you force an overlay image as part of a GUI to stay open, on top of other applications. For example I have something open and I want to make a big black square covering one part of my screen until

HotKeySet("{F10}","Terminate")
Func Terminate()
    Exit 0
EndFunc

I press that and the box will disappear.

;;;;;;;;;;; GUI ;;;;;;;;;;;;;;;;;;
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
$Form1 = GUICreate("Form1", 224, 394, 192, 124, $WS_EX_TOPMOST)
GUISetState(@SW_SHOW)
GUISetState(@SW_LOCK)
;;;;;;;; HOTKEYS ;;;;;;;;;;;;;
HotKeySet("{F10}","Terminate")
Func Terminate()
    Exit 0
EndFunc

While 1
  If $msg=$Start then Start()
WEnd

;;;;;;;; I NEED HELP HERE ;;;;;;;;;;
Func Start()
Local $sFile = "C:UsersaDesktopoverlay.jpg"
Local $gui = GUICreate ;;;;;; i dont know what i need to type ahh

I made the overlay in photoshop so its already 2048 x 1152 (my resolution), also using this WS_EX_TOPMOST it doesn't always stay on top.

I hope I expressed what I'm looking to do clear enough, I spent so much time studying the help file but failed.. ;)

Edited by skyinthesea

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