Sign in to follow this  
Followers 0
John404

Hi guys, need some simple help!

30 posts in this topic

#1 ·  Posted (edited)

Hi all, I've joined today and started learning today :D

Soo , here is what i have so far, basically the script is supposed to left click whenever it sees the color red (ff0000)

Okay so here is what I have

HotKeySet("{F6}","_Exit")


While True
$color = PixelSearch(60,0,1365,767,0xFF0000)
If $color = 0xFF0000 Then
MouseClick("left")
Sleep(30)
EndIf

WEnd

Func _Exit()
Exit
endfunc

But whenever it sees the color red, it never left clicks :oops:

Not sure if I did something wrong, or what?...

EDIT: This is what I have now:

HotKeySet("{F6}","_Exit")


While True
$color = PixelGetColor(@DesktopWidth / 2, @DesktopHeight / 2)
If $color = 16711680 Or $color = 16646144 Then
MouseClick("left")
Sleep(30)
EndIf
WEnd

Func _Exit()
Exit
endfunc

But how do I know what the color is...?

Edited by John404

Share this post


Link to post
Share on other sites



Hello John404,

Welcome to the AutoIt Forums!

First you need to fully read the Help file to understand what the functions do and return before using.

PixelSearch() looks for the color you have setup in it's parameters and returns the coordinates of that color pixel in an array, not the color for each pixel it searches.

Give this a whirl and see what it does for you!

HotKeySet("{F6}","_Exit")

While True
     $color = PixelSearch(60,0,1365,767,0xFF0000) ;Read Help file for what functions really do!
     If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
          MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
          Sleep(30)
     EndIf
WEnd

Func _Exit()
     Exit
endfunc

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Hello John404,

Welcome to the AutoIt Forums!

First you need to fully read the Help file to understand what the functions do and return before using.

PixelSearch() looks for the color you have setup in it's parameters and returns the coordinates of that color pixel in an array, not the color for each pixel it searches.

Give this a whirl and see what it does for you!

HotKeySet("{F6}","_Exit")

While True
     $color = PixelSearch(60,0,1365,767,0xFF0000) ;Read Help file for what functions really do!
     If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
          MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
          Sleep(30)
     EndIf
WEnd

Func _Exit()
     Exit
endfunc

Wow, thanks!

Is there a way to make a toggle for this? I'm going to need this at a specific time only,

thanks a bunch!

Share this post


Link to post
Share on other sites

Is there a way to make a toggle for this?

Yes, Read HotKeySet in your help file. It has a prime example for creating a toggle with the function example 'TogglePause'


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Yes, Read HotKeySet in your help file. It has a prime example for creating a toggle with the function example 'TogglePause'

I can't find it.

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

What can you not find? your help file, or the function in it?

Edit: Typo

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#7 ·  Posted (edited)

What can you not find? your help file, or the function in it?

Edit: Typo

The function in it, I found the help file.

Anyways, I took a look at the website and this is what I got

HotKeySet("{F7}", "TogglePause")


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

But whenever I hit F7, the tool just stops.

So the whole code now looks like this

HotKeySet("{F6}","_Exit")
HotKeySet("{F7}", "TogglePause")

While True
$color = PixelSearch(60,0,1365,767,0xFF0000) ;Read Help file for what functions really do!
If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
Sleep(30)
EndIf
WEnd

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func _Exit()
Exit
EndFunc
Edited by John404

Share this post


Link to post
Share on other sites

In your help file there is 4 tabs in the indexes on the left side. Choose the 2nd one actually labeled 'Index' and Enter the phrase 'hotkeyset' and it should put it right at the top of the index choices for you to double click on. :D


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

In your help file there is 4 tabs in the indexes on the left side. Choose the 2nd one actually labeled 'Index' and Enter the phrase 'hotkeyset' and it should put it right at the top of the index choices for you to double click on. :oops:

Thanks :rip: I'll be using this

I've followed the tut (it's the same one as on the website), but it still terminates the script! :D

Share this post


Link to post
Share on other sites

If it's terminating your script or giving you results less than what you desire, look into your code and find what is terminating it and correct it. If you have problems locating the error, then post your code and ask for help again.


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

If it's terminating your script or giving you results less than what you desire, look into your code and find what is terminating it and correct it. If you have problems locating the error, then post your code and ask for help again.

Hi, it's still the same thing

I honestly don't know what's causing it :D

HotKeySet("{F6}","_Exit")
HotKeySet("{F7}", "TogglePause")

While True
$color = PixelSearch(60,0,1365,767,0xFF0000) ;Read Help file for what functions really do!
If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
Sleep(30)
EndIf
WEnd

Func TogglePause()
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func _Exit()
Exit
EndFunc

Share this post


Link to post
Share on other sites

#12 ·  Posted (edited)

Read the Error messages that popup, or if your using Scite, read the console messages at the bottom. They will help you in determining what is wrong. Especially the Scite Console messages.

You erased your _Exit() Function, but still have a HotKey assigned to it. Your script can't find it which causes the error. I highly suggest adding it back, especially on that script or you could find yourself in an infinite loop that can only be stopped by bruteforcing shutdown on your machine.

Edit: I'm sorry, I must have missed that part in your script. I do see it there. Well a simple test on my side shows your script working fine. What I suggest is using the 'AutoIt Window Info' Tool that came with your download, and obtaining the actual color with it. You might not have the correct shade of red in the Pixelsearch parameters.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Read the Error messages that popup, or if your using Scite, read the console messages at the bottom. They will help you in determining what is wrong. Especially the Scite Console messages.

You erased your _Exit() Function, but still have a HotKey assigned to it. Your script can't find it which causes the error. I highly suggest adding it back, especially on that script or you could find yourself in an infinite loop that can only be stopped by bruteforcing shutdown on your machine.

Edit: I'm sorry, I must have missed that part in your script. I do see it there. Well a simple test on my side shows your script working fine. What I suggest is using the 'AutoIt Window Info' Tool that came with your download, and obtaining the actual color with it. You might not have the correct shade of red in the Pixelsearch parameters.

No, I got that to work already. Everything is working fine, 2 things left for me to finish my project.

Okay, 1)

Lets say that there are 2 pixels on your screen that is visible, first it will click on the first red pixel, then it will drag the mouse to the second, is there any way to not let this happen? I need it to just click and that's it

2) My toggle which we are working on at the moment.

Edit: For 1, I will do a test (trial & error) :D

Edited by John404

Share this post


Link to post
Share on other sites

Okay so I've fixed the first problem in this project, it was gathering the radius of my entire desktop and there were other pixels with the exact same color, that's been fixed, thanks. :oops:

Now all I'm stuck with is the toggle, and that's really confusing me :D

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

1. So you need to drag the mousebutton while down from 1 point to another?

2. The Pause Toggle is not working, and crashing your script because you forgot to declare the variable $paused.

add

Global $Paused = False

to your script to declare it before it is used. Suggestively somewhere near the top of your script.

Edit: Been awhile since I have used a Pause toggle. Changed the declaration to include it being initialized in the False state.

Edited by Realm

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

1. So you need to drag the mousebutton while down from 1 point to another?

2. The Pause Toggle is not working, and crashing your script because you forgot to declare the variable $paused.

add

Global $Paused = False

to your script to declare it before it is used. Suggestively somewhere near the top of your script.

Edit: Been awhile since I have used a Pause toggle. Changed the declaration to include it being initialized in the False state.

Okay it stopped giving me my errors, but now when I hit F7 again it won't continue.

I was thinking about making another function and leaving that to true (Not paused)

But there has to be an easier way... so this is what I have now

HotKeySet("{F6}","_Exit")
HotKeySet("{F7}", "TogglePause")

While True
$color = PixelSearch(563,222,852,451,0xFF0000) ;Read Help file for what functions really do!
If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
Sleep(30)
EndIf
WEnd

Func TogglePause()
Global $Paused = False
$Paused = NOT $Paused
While $Paused
sleep(100)
ToolTip('Script is "Paused"',0,0)
WEnd
ToolTip("")
EndFunc

Func _Exit()
Exit
EndFunc

Suggestions?

Share this post


Link to post
Share on other sites

Try this, and note where I set my global declaration for a variable.

HotKeySet("{F6}","_Exit")
HotKeySet("{F7}", "TogglePause")

Global $Paused = False

While True
     $color = PixelSearch(60,0,1365,767,0xFF0000) ;Read Help file for what functions really do!
     If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
          MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
          Sleep(30)
     EndIf
WEnd

Func TogglePause()
     $Paused = NOT $Paused
     While $Paused
          sleep(100)
          ToolTip('Script is "Paused"',0,0)
     WEnd
     ToolTip("")
EndFunc

Func _Exit()
     Exit
endfunc

My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

Try this, and note where I set my global declaration for a variable.

HotKeySet("{F6}","_Exit")
HotKeySet("{F7}", "TogglePause")

Global $Paused = False

While True
     $color = PixelSearch(60,0,1365,767,0xFF0000) ;Read Help file for what functions really do!
     If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
          MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
          Sleep(30)
     EndIf
WEnd

Func TogglePause()
     $Paused = NOT $Paused
     While $Paused
          sleep(100)
          ToolTip('Script is "Paused"',0,0)
     WEnd
     ToolTip("")
EndFunc

Func _Exit()
     Exit
endfunc

Thank you sir!!! Project complete! :D

Thanks a lot for your help, I really appreciate it :oops: I'll start to learn from this, and hopefully be able to contribute in the future! :)

I kind of like this tool, it's much easier than java / vb.net, all of those complicated languages used to make such a simple script, I mean really...

Hey, would you happen to have any project recommendations, you know... for beginners? So I could start learning + developing neat projects + understanding what each syntax does, I've seen some of the syntaxes here and I compared it to java, so I was able to understand it right away.

Thanks again :rip:

Share this post


Link to post
Share on other sites

Your Welcome!

As for project recommendations, I would suggest finding tasks that are repetitive and seeing what you can do to accomplish them with AutoIt!


My Contributions: Unix Timestamp: Calculate Unix time, or seconds since Epoch, accounting for your local timezone and daylight savings time. RegEdit Jumper: A Small & Simple interface based on Yashied's Reg Jumper Function, for searching Hives in your registry.  

Share this post


Link to post
Share on other sites

#20 ·  Posted (edited)

Your Welcome!

As for project recommendations, I would suggest finding tasks that are repetitive and seeing what you can do to accomplish them with AutoIt!

okay.

I messed up again :/ now it's only clicking inside the colors on Scite.

What's wrong???

HotKeySet("{F6}","_Exit")
HotKeySet("{F7}", "TogglePause")

Global $Paused = False

While True
$color = PixelSearch(563,222,852,451,0xFF0000) ;Read Help file for what functions really do!
If Not @error Then ;PixelSearch returns the coordinates that if finds your color, not the color found.
MouseClick("left", $color[0], $color[1]) ;<--Needs coords to click at which are returned in an array from PixelSearch
Sleep(30)

EndIf
WEnd

Func TogglePause()
$Paused = NOT $Paused
While $Paused
Sleep(100)
WEnd
ToolTip("")
EndFunc

Func _Exit()
Exit
endfunc
Edited by John404

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this  
Followers 0