click on image text

Ask gaming related questions (AHK v1.1 and older)
mamo691
Posts: 41
Joined: 07 Jan 2024, 12:40

click on image text

13 Apr 2024, 08:33

so at the start it clicks on a coordinate. (opens game menu aka "add bonus" in the video where the images i want to find are) so in that part there could be different images from the image list showing or only one or none, doesnt matter. If it doesnt find image from the list then it tries to find other image from the list. Not break. If there is multiple images showing then it will just click randomly at one of them. (menu disappears here) and after that it will click back at the same coordinate at the start. (the one that opened the menu) and this cycle will basically repeat as long as I hold g.

Important ! :
Also there are parts where there is mouse hovering as can be seen in the video. I think that requires the mousehover code. Basically as can be seen, it will have a secondary hotkey such as j, so when I hold j, this time again, same process basically, at the start we click at a coordinate (add clause button in the video) and then the menu opens, but this time we will mouse hover on the image. Then after that when it detects other image it clicks on that image. Same stuff i guess but with mouse hover. If it doesnt find image then it tries to find other image from the list. Not break. If it cant find any image, wont do anything.

video: https://gyazo.com/216f1e8458f1af8688ba7c1626e6ddda


this code i have doesnt work as intended : (experimental, im going to have like 20 images here.)

Code: Select all

g::
	CoordMode, Mouse
	CoordMode, Pixel
	imageList := ["C:\Users\izzet\Desktop\Yeni klasör\goalbonus.png", "C:\Users\izzet\Desktop\Yeni klasör\assistbonus.png"]
	for each, image in imageList {
		ImageSearch, FoundX, FoundY, 1114, 328, 1450, 800, % "*10 " image
		if (ErrorLevel = 2) {
			MsgBox, % "Problem loading " image
			ExitApp
		}
		if ErrorLevel {
			Send, {Click}
			Sleep, 200
		} else {
			MouseGetPos, xpos, ypos, WinUMID
			MouseClick, Left, FoundX, FoundY
			WinActivate, ahk_id %WinUMID%
			MouseMove, xpos, ypos
		}
	}
return
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: click on image text

13 Apr 2024, 09:41

Hello,

I would take a structured and stepwise approach to your debugging process.
  1. Before searching for many images, see if you can find just one. This tells you whether you are using ImageSearch correctly. Test ImageSearch in 3 lines. The test requires no If statements; you can simply report the ErrorLevel from the search.
  2. Display or inspect the values of your variables and conditions.
  3. I suppose that if you want to select an image among all found images, then you will first need to find all of the images, and then select one of them after you find all of them.
  4. "Doesn't work" says nothing much. It does not report what your script actually does when you run it. This information would be important for anyone who is debugging the script.
  5. A mouse cursor can be over a window while a different window is active. You can use WinGet or WinActive (or WinExist) to get information about the active window.
Best of luck!
mamo691
Posts: 41
Joined: 07 Jan 2024, 12:40

Re: click on image text

13 Apr 2024, 09:54

it doesnt meet my requirements i dont think i have to really thoroughly explain it since its a simple code. It's inaccurate from time to time and doesnt click on the image although it clicks a random place thats away from the image. It breaks when it cant find the first color or second color i believe and that is not what I want. I strictly mentioned that. I would also appreciate it rather than just giving me a theory but rather give me links to posts that would actually help me learn would be very nice because as you can clearly tell i am not a coder and I know 0 thing about coding.
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: click on image text

13 Apr 2024, 10:16

  1. I provided a link to a test script. If I were writing the script myself, I would be starting with that test.
  2. If you get a click at a "random" location, then your ErrorLevel is presumably 1, and the clicking happens in place, exactly as you have coded it to happen. The test script would illuminate that issue by displaying the ErrorLevel. You currently do not know what ErrorLevel your search is returning.
  3. If you believe that your intent can be magically understood without your description of it, my only comment is that this is sometimes true and sometimes not true. Examining a few other posts will quickly confirm this.
  4. Your loop breaks only with one of two conditions. The first is when the ErrorLevel is two, when the script exits. The second is when the loop finishes. No loops or If statements are needed to understand the ErrorLevel from your search.
  5. If you know nothing about coding, then you might want to start with the test script or at least a simpler script as described. This will simplify and speed your debugging.
  6. Remove the MouseGetPos and MouseMove so that you can understand whether the search works. After the search works, you can add more commands. At that time, instead of getting the HWND under the mouse, get the HWND of the active window. This is given by WinActive("A").
gregster
Posts: 9068
Joined: 30 Sep 2013, 06:48

Re: click on image text

13 Apr 2024, 18:43

Chunjee wrote:
13 Apr 2024, 12:21
For games you can post here: viewforum.php?f=18
Sure, new gaming topics should be created there. For already existing discussions like this, it is much more preferable to just move them.
(I just did that, although Imagesearch questions are not necessarily limited to games.)
mamo691
Posts: 41
Joined: 07 Jan 2024, 12:40

Re: click on image text

14 Apr 2024, 07:41

@mikeyww can you just code it for me
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: click on image text

14 Apr 2024, 07:56

This script can be used to troubleshoot.

Code: Select all

#Requires AutoHotkey v1.1.33.11
dir       := A_Desktop "\Yeni klasör"
imageList := ["goalbonus.png", "assistbonus.png"]

g::
CoordMode Mouse
CoordMode Pixel
tip := ""
For each, image in imageList {
 ; ImageSearch, FoundX, FoundY, 1114, 328, 1450, 800, % "*10 " image
 ImageSearch px, py, 0, 0, A_ScreenWidth, A_ScreenHeight, % dir "\" image
 ToolTip % tip .= ErrorLevel
 Switch ErrorLevel {
  Case 0:
   MouseGetPos x, y
   WinActive("A")
   MouseClick,, px, py
   WinActivate
   MouseMove x, y
  Case 1:
   Click
   MsgBox 48, Warning, % "Image not found!`n`n" image
  Case 2:
   MsgBox 48, Error, % "An error occurred with the image search.`n`n" image
 }
}
Return
mamo691
Posts: 41
Joined: 07 Jan 2024, 12:40

Re: click on image text

14 Apr 2024, 09:31

@mikeyww I am facing problems with your code.

https://gyazo.com/89ed0cf83e43b57189f569b2b8116643 Video on why your code is not doing the job for me at all

The clicks are not exactly on the image and are off, I dont know why it is that way. Btw I trimmed your code and in this message, I will put the code that I used. As I said in the post, the code I gave first is merely experimental, I will have a bunch of images in the list and etc.. As I also said, I want the script to run as long as I am holding g and when I stop holding it will stop. I believe your missed this part because your code doesnt allow me this. With your code, I have random stuff popping on my screen on white, its numbers, I dont want that. I also dont need error message boxes. When I used your code, it made my clicks unstable for some reason, i have no idea why that happened.

TLDR'ing my earlier message : I want two combinations with one working while i hold down the key "g" and the other working while i hold down the key "j".
the first combination will work in this way: So as can be seen in the video, all my images that im trying to find are located in a small game menu that can be opened with clicking at a game button which for this combination fyi, "add bonus." What the code will do is, when I hold g, it will send 1 click to add bonus button's coordinates which I will set myself. So its a simple click on coordinate. So then, the menu will open, and so the code might find no images from my list in the menu, which in that case will do nothing. And I mean it, strictly nothing. If it finds multiple images, it will click at one of them randomly. So now i want to say, the way the game works is as you can see in the video, when you click at lets say, "goal bonus." from the add bonus menu, what happens is that goal bonus gets added and it cant get added again, the image of it also changes to a darkish tone, and so it cant be clicked again by the script anyways. Also when you add a bonus or a clause from the menus, the menu disappears so you have to open it again. So here comes my crucial request which your script doesnt fulfill, after the script clicks on a found image, it will send click to the coordinate of the "add bonus" button which again, I will set. And remember all of this is happening as I'm holding the key g and if i stop holding it, the whole thing stops. So then, it will look for images again and this will repeat till it cant find images. In that case, as you'd imagine, the menu is left open and so he strictly doesnt take any action if it cant find anything but the click on coordinate at the start.

Now for the second combination, its literally the same. Refer to the video here: https://gyazo.com/216f1e8458f1af8688ba7c1626e6ddda - So what i want is that this time it will work as i hold down the "j" button. This time, which you can see on the video, we will be sending the click on coordinate at the start to the "add clause" button. Now here, we will have mousehover function i believe. There are combined goals and assists, there are goals, and, there are assists. When you hover on them, as can be seen in the video, a list of numbers pop up next to them. So for the three clauses aka combined g/a, g, and, a, (im saying them in short terms) the mouse will just hover them and choose 2 clauses from the new list of numbers for each clause. If you didnt really understand me, think of it this way: so in the video, forward it a little to the point where im doing stuff with the add clause, so okay all mouse movements im doing there i want them to be automated. I hope this visually breaks it down for u because i got very long with my explanation.

Code: Select all

#Requires AutoHotkey v1.1.33.11
dir       := A_Desktop "\Yeni klasör"
imageList := ["goalbonus.png", "assistbonus.png"]

$g::
CoordMode Mouse
CoordMode Pixel
tip := ""
For each, image in imageList {
 ; ImageSearch, FoundX, FoundY, 1114, 328, 1450, 800, % "*10 " image
 ImageSearch px, py, 0, 0, A_ScreenWidth, A_ScreenHeight, % dir "\" image
 ToolTip % tip .= ErrorLevel
 Switch ErrorLevel {
  Case 0:
   MouseGetPos x, y
   WinActive("A")
   MouseClick,, px, py
   WinActivate
   MouseMove x, y
 }
}
Return
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: click on image text

14 Apr 2024, 10:00

I can just offer advice about how to approach your script.
  1. The script that I posted is designed to help you understand whether your ImageSearch works. The ToolTip is optional and can be removed. It shows you the results (ErrorLevel) of the searches, so that you can troubleshoot. If you are seeing a zero but a click in the wrong place, then you can add lines that show you the coordinates that were found. This enables you to understand the search in more detail. The 1 means that the image was not found. You have the wrong image, the wrong time for it to appear, etc.
  2. There is no reason to remove Case 2 from your script because the user should be warned if the ErrorLevel is 2. This means that something unexpected is happening. In many cases, it means that the local image file does not exist or could not be accessed.
  3. I do not know why you are using a dollar prefix with your hotkey.
  4. To create a loop, you could add a SetTimer, or a While statement with GetKeyState() to check your hotkey's state. I would avoid doing this until you have fixed your image search.
  5. Before you add new hotkeys, I would fix the one that you have.
  6. If you need to wait for an image to appear, your current script will not be doing that. You would probably want a new timer or loop to accomplish that. Hundreds or thousands of scripts have been posted that wait for images to appear, so you could very likely adapt one or more of them.
Enjoy!
mamo691
Posts: 41
Joined: 07 Jan 2024, 12:40

Re: click on image text

14 Apr 2024, 19:25

@mikeyww can you do the fixes for me so I can study your code ig ?
User avatar
mikeyww
Posts: 27133
Joined: 09 Sep 2014, 18:38

Re: click on image text

14 Apr 2024, 20:59

You first asked for links to a post to help you learn, so I provided that. You then asked for a script, so I provided that. Your response to all of the posts is that they do not meet your requirements, and the code is not doing the job for you at all. OK. I will leave the rest to you here, though others may be able to chime in with better solutions.

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: No registered users and 27 guests