receive an acknowledgment

Get help with using AutoHotkey and its commands and hotkeys
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

receive an acknowledgment

28 Apr 2020, 18:59

I have a script that makes tee times. Upon entry into the online booking program, the available tee times for today are shown. The user then inputs the date that he/she wants. The screen is refreshed with that day's available tee times. Right now, my script sleeps for a few seconds and then assumes that the new screen has been displayed. What I would like to do is receive an acknowledgment that the is displayed so I only have to wait a minimum amount of time. The script runs at midnight, so it is unattended.
A side note: This is a sign of the times. I have been running this script for a couple of years with no problem. But, because there is so little to do, people are setting their alarm for just before midnight to make their tee times. All the times up until 3 will be gone within 5 seconds. So, that is why I need to have my script wake as soon as possible.
I really appreciate any help. I have tried to research this situation but I can't find the answer. I suspect others have encountered it and I am not searching with the correct words.
btw, I feel very safe on the golf course. They have implemented rules in conjunction with our health department to minimize the risk to us.
btw2, I love autohotkey
User avatar
boiler
Posts: 5614
Joined: 21 Dec 2014, 02:44

Re: receive an acknowledgment

28 Apr 2020, 21:59

The best way would be to automate the website using Internet Explorer and the COM interface or one of the other similar methods for other browsers, which provide methods for knowing when a page has finished loading. I remember from your earlier posts, however, that you’ve done a lot with ImageSearch, so it’s probably easiest for your script at this point to just use ImageSearch for this as well.

Your browser’s refresh button (looks like a circular arrow in Chrome) will take on a different image while a page is loading, so you would just search in a loop for the refresh button to return to its original state to know when the page has finished loading.
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

29 Apr 2020, 11:17

My script uses Firefox, but there is no spinning wheel when the window is being refreshed with the times for the new day.
I haven't used COM Objects. Perhaps that is the answer. I would like to learn about them. I have read the instructions in the Autohotkey documentation, but I wonder if there is another introductory tutorial that I could read to bring me up to speed. Would I create the object and then test for it or is there an object I could call to test if the screen is refreshed.
Thank you again for your help.
User avatar
boiler
Posts: 5614
Joined: 21 Dec 2014, 02:44

Re: receive an acknowledgment

29 Apr 2020, 15:20

I'm not talking about the spinning "busy" wheel. I'm talking about the stationary refresh button. Isn't it showing something else while your tee times are refreshing and then it is visible again after it completes? Here's an image of what I'm referring to from my Firefox browser:
firefox refresh.png
firefox refresh.png (457 Bytes) Viewed 696 times

If you want to learn about automating web pages with COM, here is a good tutorial. You wouldn't test for the presence of a certain object. You would just look for times when the browser is busy and then no longer busy. But if your page isn't actually going through a refresh because there is some javascript code just updating it automatically, then it might not be able to do anything to detect it. But as I mentioned, that only works with Internet Explorer. Look into Selenium if you want to automate Firefox (and others).

A totally separate way that would work no matter if your refresh button changes or not would be to capture the current image of the displayed page, and then you search for that as the reference image, and when it doesn't find it, you know the content has changed. I have used that approach successfully to know when applications of various types have changed what they are displaying.
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

29 Apr 2020, 18:25

The confusion stems from my use of the word refresh. I didn't mean I hit the refresh button. I enter the new date that I want and hit enter.
I think your idea of capturing the image is exactly what I need. I have used the snipping tool to capture images manually in the past. Is there a more automated way within autohotkey? I admit to being a lazy here and asking the question without having researched it.
I will study the tutorial you recommended and research Selenium
Thank you again for your time and help.
User avatar
boiler
Posts: 5614
Joined: 21 Dec 2014, 02:44

Re: receive an acknowledgment

29 Apr 2020, 19:01

tomstuber wrote: The confusion stems from my use of the word refresh. I didn't mean I hit the refresh button. I enter the new date that I want and hit enter.
I’m not saying that you hit the refresh button. What I’m asking is after you enter the new date and hit the enter key, does that refresh button become some other image until the page is done loading (even though you didn’t click on it) and return to its normal state when the page loading is complete? That is exactly what happens with other sites.

For example, go to google in your Firefox browser, type something in the search bar, hit the enter key, and you’ll see that refresh button change while it’s loading to the results (eventually to an X) until the results page is fully loaded, then it becomes the normal refresh button like I showed above again. Knowing that, I can easily write a script to know when that page has finished loading, which sounds exactly like what you’re asking for here.
tomstuber wrote: I think your idea of capturing the image is exactly what I need. I have used the snipping tool to capture images manually in the past. Is there a more automated way within autohotkey? I admit to being a lazy here and asking the question without having researched it.
Use the CaptureScreen function by Linear Spoon found at this thread. Make sure to use his version, not the others in that thread.
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

29 Apr 2020, 22:10

The refresh arrow does not change when I key the date and hit enter. Too bad that would have been an easy test
However, the CaptureScreen script that you reference looks perfect. I should be able to take it from here.
Learning and using AutoHotkey has been good mental exercise for an old programmer's mind just as I feel walking 18 holes is good physical exercise.
Thank you again for all the help. I hope I don't have to bother you again.
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

30 Apr 2020, 14:41

Boiler,
Could you give me some more help, please.
I have the following code:

Code: Select all

TimesLoop:	   ;Loop through the number of tee times to be made
	Loop %NoTimes%
	{	
SearchTime: 	
		TimeNum := 1
		Loop, %NumPossTimes%                     ; Try each possible time.  
		{
		Time := TeeTime[TimeNum]
		ImageSearch, Px, Py, %TimBegX%, %TimBegY%, %MonRight%, %MonBottom%, *110 *Trans0x00FF00 %Time%   
		
			If ErrorLevel=1 ;Didn't find it
				TimeNum += 1     ; Try next tee time
			else
			If ErrorLevel=0  ; Found a tee time
			{
				Click, %Px%, %Py%                 ; Click on The tee time
				Sleep, 1000
				SendInput, {End}   ; Go to bottom of page to look for Book Time button
				Sleep, 100
				ImageName := "BookTime.PNG"
				ImageSearch, Px, Py, %TimBegX%, %TimBegY%, %MonRight%, %MonBottom%, *110 %ImageName%  
				If ErrorLevel = 0
					{
					Click, %Px%, %Py%                 
					Sleep, 2000   ; wait this value is set before the call to FindImage
					FormatTime, LogTime, , HH:mm:ss
					FileAppend %LogDate% %LogTime% File = %Time% `n,Logfile.txt
					break    ; exit loop because we found the time
					} ; If ErrorLevel = 0 for BookTime
			}  ; If ErrorLevel = 0
		}   ; Loop NumPossTimes, Didn't find time on page so try next time

	If ErrorLevel ; Either didn't find any of the times or Invalid file name
	{
		ImageName := "No Times Found"
		gosub, ChkErr
	}
[Mod edit: [code][/code] tags added]

I am searching for the BookTime Button on the popup window, but the search doesn't find it. I have tried other images as well, to no avail.
I feel the background window is still the active window because the SendInput, {End} statement sends the background window to the bottom rather than the foreground window which contains the BookTime button. I have worked around this problem, previously, by tabbing to the BookTime button and sending and Enter statement. But, in order to test whether a tee time is still available I need to test for an image on the screen in the foreground.
btw, this is a different area of code than my previous question. I need to resolve this before I move to that.
btw#2: Last year when you helped me you said you were going to try to get in some golf. Did you make it out?
I am attaching a picture of the screen as it appears when the above code is executing. Thank you again
Forum.png
Forum.png (272.82 KiB) Viewed 608 times
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

30 Apr 2020, 16:51

Boiler,
Nevermind. I ran this on a different computer and it ran fine. I am not sure what that says.
Thanks again for your help
User avatar
boiler
Posts: 5614
Joined: 21 Dec 2014, 02:44

Re: receive an acknowledgment

30 Apr 2020, 17:25

I’d be curious to know if the one it didn’t work on had a really high definition monitor, more importantly, had a scaling factor in Windows of something other than 100%. Right-click on an open spot on the desktop and choose “Display settings.”
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

01 May 2020, 11:42

The scaling factor is 100%
The display resolution is 1920 x 1080

It is a very old Desktop that I don't use for anything other than scheduling my tee times. I set Task Scheduler to wake up at midnight and book the times. I have a couple of other newer computers that it works fine on, so it's not a show stopper.

I hope to try your recommendation for capturing an image on the screen and testing for it to change this weekend. I will let you know how it goes.

Thanks again for the help
leeblee
Posts: 2
Joined: 07 May 2020, 09:44

Re: receive an acknowledgment

07 May 2020, 10:30

this is awesome, i was hoping you would be able to walk me through this at some point, i have been trying to figure out how to do this for a long time
leeblee
Posts: 2
Joined: 07 May 2020, 09:44

Re: receive an acknowledgment

07 May 2020, 10:44

i cannot send a private message, are you able to message me or email me to help me out with this?
tomstuber
Posts: 16
Joined: 08 Apr 2019, 19:01

Re: receive an acknowledgment

10 Jul 2020, 11:54

leeblee,
My apologies. I did not see this post. I know it has been months, but if I can help you with something let me know.

Return to “Ask For Help”

Who is online

Users browsing this forum: BIGZIPZ, Bing [Bot], boiler, doubledave22, JaydeNpie, jvlz, Smile_ and 54 guests