Sargerasrex wrote: ↑28 Oct 2019, 09:36
... My end goal is to create a script that will detect a certain predefined image on the top right area of my screen and then send a keystroke that I indicate in the script. ...
You don't need to compile anything.
1. Find the Lib folder on your computer, which is inside the Autohotkey folder where Autohotkey.exe resides.
2. Place the file FindClick.ahk in the Lib folder. Now any script you run will be able to use the function from FindClick. (Alternatively, you could copy-paste the complete contents of FindClick.ahk into your new script that will be using it.)
3. Create a new script anywhere you like, containing just
FindClick() (or run that line in some other script: it doesn't matter).
4. Run the script. Now you will get the FindClick interface, and you will be able to pick an area on the screen and save it as an image from the interface.
5. Make sure to check "Copy code to clipboard"; and add
n0 to the options ("click 0 times on the image"), otherwise the mouse will click on the image whenever it is found.
6. After clicking Save, you will get code on your clipboard, like
FindClick("D:\Programs\AutoHotkey\Graphics\NewFile", "n0"). You can use that code in a script to have the script look for the image. You can use it like this:
Code: Select all
Image1Found := FindClick("D:\Programs\AutoHotkey\Graphics\NewFile", "n0")
If (Image1Found)
{
SoundBeep, 300, 100
}
When you execute this code, it will search for the image, and, if the image is found, it will store the coördinates of its location on the screen in the variable
Image1Found. If the image is not found, the variable will be made empty.
Then the
If checks whether there is anything inside the variable; if so, it will produce a sound beep.
You may want to "watch" for an image to appear. You could use the Watch option in FindClick, but I don't know how that works. It may be safer to use the normal method, a timer that executes the code above, every e.g. 1000 milliseconds (lower this period to make the script respond faster):
Code: Select all
SetTimer, SearchForImages, 1000
SearchForImages(){
static SearchIsBusy
If ( SearchIsBusy = True)
{
Return
}
SearchIsBusy := True
Image1Found := FindClick("D:\Programs\AutoHotkey\Graphics\Image1", "n0")
If (Image1Found)
{
SoundBeep, 300, 100
}
Image2Found := FindClick("D:\Programs\AutoHotkey\Graphics\Image2", "n0")
If (Image2Found)
{
SoundBeep, 600, 100
}
SearchIsBusy := False
}
I've also added a check
SearchIsBusy, to make sure the search isn't triggered again while it is still busy; this could happen if you set the period of the timer to a very low number of milliseconds.
Note: of course the code above won't work on your computer, until you have generated your own
FindClick(... and put it in there.
Good luck! Do let me know if you still can't get it to work.
P.S. Chapeau for including your end goal in your question; many people forget this, but it makes it much easier to help.
P.P.S. You used
Send {w}, but normal letters don't need to be included in braces with
Send. Though I don't think it hurts either.